in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
char buf[5];
- sz += ucs4ToUTF8(*in, buf);
+ sz += ucs4ToUTF8(*(const unsigned char*)in, buf);
in++;
in_len--;
}
in = src;
in_len = bytes;
while ((in_len > 0) && (*in != '\0')) {
- out += ucs4ToUTF8(*in, out);
+ out += ucs4ToUTF8(*(const unsigned char*)in, out);
in++;
in_len--;
}
const wchar_t *utf16;
};
+struct _latin1utf8 {
+ const char *latin1;
+ const char *utf8;
+};
+
struct _utf8utf16 {
const char *utf8;
const wchar_t *utf16;
{ 0x110200, L"\xfffd" },
};
+struct _latin1utf8 latin1utf8[] = {
+ { "abc", "abc" },
+ { "\xe5\xe4\xf6", "\xc3\xa5\xc3\xa4\xc3\xb6" },
+ { "???", "\xe2\x98\xb9\xe2\x98\xba\xe2\x98\xbb" },
+ { "?", "\xe5\xe4" },
+};
+
struct _utf8utf16 utf8utf16[] = {
{ "abc", L"abc" },
{ "\xc3\xa5\xc3\xa4\xc3\xb6", L"\xe5\xe4\xf6" },
}
}
+ for (i = 0;i < ARRAY_SIZE(latin1utf8);i++) {
+ /* Expected failure? */
+ if (strchr(latin1utf8[i].latin1, '?') != NULL)
+ continue;
+
+ out = rfb::latin1ToUTF8(latin1utf8[i].latin1);
+ if (strcmp(out, latin1utf8[i].utf8) != 0) {
+ printf("FAILED: latin1ToUTF8() #%d\n", (int)i+1);
+ failures++;
+ }
+ rfb::strFree(out);
+ }
+
+ for (i = 0;i < ARRAY_SIZE(latin1utf8);i++) {
+ out = rfb::utf8ToLatin1(latin1utf8[i].utf8);
+ if (strcmp(out, latin1utf8[i].latin1) != 0) {
+ printf("FAILED: utf8ToLatin1() #%d\n", (int)i+1);
+ failures++;
+ }
+ rfb::strFree(out);
+ }
+
for (i = 0;i < ARRAY_SIZE(utf8utf16);i++) {
/* Expected failure? */
if (wcscmp(utf8utf16[i].utf16, L"\xfffd") == 0)