mirror of
https://github.com/irssi/irssi.git
synced 2026-08-10 12:23:37 +02:00
Preliminary support for UTF8 with /SET term_utf8 ON. Input line is still
messed up, but lines should wrap properly in text buffer. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2354 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
0cdc8a7f6a
commit
46b318b831
7 changed files with 104 additions and 8 deletions
64
src/fe-text/utf8.c
Normal file
64
src/fe-text/utf8.c
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
|
||||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue