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 < 0x10000) |
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 |
|
else if (*string < 0x200000) |
98 |
|
{ |
99 |
|
if (size < 4) |
100 |
|
break; |
101 |
|
*buf++ = 0xF0 | (*string >> 18); |
102 |
|
*buf++ = 0x80 | (*string >> 12 & 0x3F); |
103 |
|
*buf++ = 0x80 | (*string >> 6 & 0x3F); |
104 |
|
*buf++ = 0x80 | (*string & 0x3F); |
105 |
|
size -= 2; |
106 |
|
} |
107 |
|
|
108 |
|
string++; |
109 |
|
} |
110 |
|
|
111 |
|
*buf = '\0'; |
112 |
|
|
113 |
|
return convert_buffer; |
114 |
|
} |
115 |
|
|
116 |
int |
int |
117 |
vchannel_open() |
vchannel_open() |
278 |
|
|
279 |
return string; |
return string; |
280 |
} |
} |
281 |
|
|
282 |
|
const char * |
283 |
|
vchannel_strfilter_unicode(const unsigned short *string) |
284 |
|
{ |
285 |
|
return vchannel_strfilter((char *) unicode_to_utf8(string)); |
286 |
|
} |