patch from: Mikhail Gusarov <dottedmag@dottedmag.net>

evas_common_font_utf8_get_prev currently works correctly only on an
ASCII symbols. For non-ASCII it just returns random garbage somehow
constructed from a string.

Attached patch makes it work according to the comment at the start.



SVN revision: 41292
This commit is contained in:
Mikhail Gusarov 2009-07-10 06:06:37 +00:00 committed by Carsten Haitzler
parent 8106bf6d44
commit d6af88ef6c
1 changed files with 7 additions and 40 deletions

View File

@ -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;