55 |
vchannel_write(buf); |
vchannel_write(buf); |
56 |
} |
} |
57 |
|
|
58 |
|
#define CONVERT_BUFFER_SIZE 1024 |
59 |
|
static char convert_buffer[CONVERT_BUFFER_SIZE]; |
60 |
|
|
61 |
|
const char * |
62 |
|
unicode_to_utf8(const unsigned short *string) |
63 |
|
{ |
64 |
|
unsigned char *buf; |
65 |
|
size_t size; |
66 |
|
|
67 |
|
buf = (unsigned char *) convert_buffer; |
68 |
|
size = sizeof(convert_buffer) - 1; |
69 |
|
|
70 |
|
/* We do not handle characters outside BMP (i.e. we can't do UTF-16) */ |
71 |
|
while (*string != 0x0000) |
72 |
|
{ |
73 |
|
if (*string < 0x80) |
74 |
|
{ |
75 |
|
if (size < 1) |
76 |
|
break; |
77 |
|
*buf++ = (unsigned char) *string; |
78 |
|
size--; |
79 |
|
} |
80 |
|
else if (*string < 0x800) |
81 |
|
{ |
82 |
|
if (size < 2) |
83 |
|
break; |
84 |
|
*buf++ = 0xC0 | (*string >> 6); |
85 |
|
*buf++ = 0x80 | (*string & 0x3F); |
86 |
|
size -= 2; |
87 |
|
} |
88 |
|
else if ((*string < 0xD800) || (*string > 0xDFFF)) |
89 |
|
{ |
90 |
|
if (size < 3) |
91 |
|
break; |
92 |
|
*buf++ = 0xE0 | (*string >> 12); |
93 |
|
*buf++ = 0x80 | (*string >> 6 & 0x3F); |
94 |
|
*buf++ = 0x80 | (*string & 0x3F); |
95 |
|
size -= 2; |
96 |
|
} |
97 |
|
|
98 |
|
string++; |
99 |
|
} |
100 |
|
|
101 |
|
*buf = '\0'; |
102 |
|
|
103 |
|
return convert_buffer; |
104 |
|
} |
105 |
|
|
106 |
int |
int |
107 |
vchannel_open() |
vchannel_open() |
268 |
|
|
269 |
return string; |
return string; |
270 |
} |
} |
271 |
|
|
272 |
|
const char * |
273 |
|
vchannel_strfilter_unicode(const unsigned short *string) |
274 |
|
{ |
275 |
|
return vchannel_strfilter((char *) unicode_to_utf8(string)); |
276 |
|
} |