mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
|
|
||
|
#define UTF8_COMPUTE(Char, Mask, Len) \
|
||
|
if (Char < 128) \
|
||
|
{ \
|
||
|
Len = 1; \
|
||
|
Mask = 0x7f; \
|
||
|
} \
|
||
|
else if ((Char & 0xe0) == 0xc0) \
|
||
|
{ \
|
||
|
Len = 2; \
|
||
|
Mask = 0x1f; \
|
||
|
} \
|
||
|
else if ((Char & 0xf0) == 0xe0) \
|
||
|
{ \
|
||
|
Len = 3; \
|
||
|
Mask = 0x0f; \
|
||
|
} \
|
||
|
else if ((Char & 0xf8) == 0xf0) \
|
||
|
{ \
|
||
|
Len = 4; \
|
||
|
Mask = 0x07; \
|
||
|
} \
|
||
|
else if ((Char & 0xfc) == 0xf8) \
|
||
|
{ \
|
||
|
Len = 5; \
|
||
|
Mask = 0x03; \
|
||
|
} \
|
||
|
else if ((Char & 0xfe) == 0xfc) \
|
||
|
{ \
|
||
|
Len = 6; \
|
||
|
Mask = 0x01; \
|
||
|
} \
|
||
|
else \
|
||
|
Len = -1;
|
||
|
|
||
|
#define UTF8_GET(Result, Chars, Count, Mask, Len) \
|
||
|
(Result) = (Chars)[0] & (Mask); \
|
||
|
for ((Count) = 1; (Count) < (Len); ++(Count)) \
|
||
|
{ \
|
||
|
if (((Chars)[(Count)] & 0xc0) != 0x80) \
|
||
|
{ \
|
||
|
(Result) = -1; \
|
||
|
break; \
|
||
|
} \
|
||
|
(Result) <<= 6; \
|
||
|
(Result) |= ((Chars)[(Count)] & 0x3f); \
|
||
|
}
|
||
|
|
||
|
void get_utf8_char(const unsigned char **ptr)
|
||
|
{
|
||
|
int i, mask = 0, len;
|
||
|
unsigned int result;
|
||
|
unsigned char c = (unsigned char) **ptr;
|
||
|
|
||
|
UTF8_COMPUTE(c, mask, len);
|
||
|
if (len == -1)
|
||
|
return;
|
||
|
|
||
|
UTF8_GET(result, *ptr, i, mask, len);
|
||
|
if (result == -1)
|
||
|
return;
|
||
|
|
||
|
*ptr += len-1;
|
||
|
}
|