diff --git a/legacy/evas/src/lib/engines/common/evas_font_main.c b/legacy/evas/src/lib/engines/common/evas_font_main.c index 8c7e0a7084..ee8bf34cdd 100644 --- a/legacy/evas/src/lib/engines/common/evas_font_main.c +++ b/legacy/evas/src/lib/engines/common/evas_font_main.c @@ -193,52 +193,19 @@ evas_common_font_utf8_get_prev(const unsigned char *buf, int *iindex) * * Returns 0 to indicate there is no prev char */ - int index = *iindex, len, r; - unsigned char d, d2, d3, d4; + int index = *iindex; if (index <= 0) return 0; - d = buf[index--]; + /* First obtain the codepoint at iindex */ + int r = evas_common_font_utf8_get_next(buf, &index); + + /* Next advance iindex to previous codepoint */ + index = *iindex; + index--; while ((index > 0) && ((buf[index] & 0xc0) == 0x80)) index--; - len = *iindex - index; - - if (len == 1) - r = d; - else if (len == 2) - { - /* 2 bytes */ - d2 = buf[index + 1]; - r = d & 0x1f; /* copy lower 5 */ - r <<= 6; - r |= (d2 & 0x3f); /* copy lower 6 */ - } - else if (len == 3) - { - /* 3 bytes */ - d2 = buf[index + 1]; - d3 = buf[index + 2]; - r = d & 0x0f; /* copy lower 4 */ - r <<= 6; - r |= (d2 & 0x3f); - r <<= 6; - r |= (d3 & 0x3f); - } - else - { - /* 4 bytes */ - d2 = buf[index + 1]; - d3 = buf[index + 2]; - d4 = buf[index + 3]; - r = d & 0x0f; /* copy lower 4 */ - r <<= 6; - r |= (d2 & 0x3f); - r <<= 6; - r |= (d3 & 0x3f); - r <<= 6; - r |= (d4 & 0x3f); - } *iindex = index; return r;