36 #if !defined(ARRAY_SIZE) 37 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 56 {2, { {0xC2, 0xDF}, {0x80, 0xBF} } },
57 {3, { {0xE0, 0xE0}, {0xA0, 0xBF}, {0x80, 0xBF} } },
58 {3, { {0xE1, 0xEC}, {0x80, 0xBF}, {0x80, 0xBF} } },
59 {3, { {0xED, 0xED}, {0x80, 0x9F}, {0x80, 0xBF} } },
60 {3, { {0xEE, 0xEF}, {0x80, 0xBF}, {0x80, 0xBF} } },
61 {4, { {0xF0, 0xF0}, {0x90, 0xBF}, {0x80, 0xBF}, {0x80, 0xBF} } },
62 {4, { {0xF1, 0xF3}, {0x80, 0xBF}, {0x80, 0xBF}, {0x80, 0xBF} } },
63 {4, { {0xF4, 0xF4}, {0x80, 0x8F}, {0x80, 0xBF}, {0x80, 0xBF} } },
81 const char *
rc = NULL;
87 if ((data[0] & 128) == 0)
89 else if ((data[0] & 0xF0) == 0xF0)
91 else if ((data[0] & 0xE0) == 0xE0)
102 for (j = 0; j < charlen; ++j)
131 const char* curdata = NULL;
135 if (len == 0 || data == NULL)
141 while (curdata && (curdata < data + len))
144 rc = curdata != NULL;
171 #if defined(UNIT_TESTS) 180 tests valid_strings[] =
183 {7, {0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E} },
184 {3, {
'f', 0xC9, 0xB1 } },
185 {9, {0xED, 0x95, 0x9C, 0xEA, 0xB5, 0xAD, 0xEC, 0x96, 0xB4} },
186 {9, {0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E} },
187 {4, {0x2F, 0x2E, 0x2E, 0x2F} },
188 {7, {0xEF, 0xBB, 0xBF, 0xF0, 0xA3, 0x8E, 0xB4} },
191 tests invalid_strings[] =
194 {5, {0x2F, 0xC0, 0xAE, 0x2E, 0x2F} },
195 {6, {0xED, 0xA1, 0x8C, 0xED, 0xBE, 0xB4} },
199 int main (
int argc,
char *argv[])
203 for (i = 0; i <
ARRAY_SIZE(valid_strings); ++i)
207 printf(
"valid test %d failed\n", i);
211 printf(
"valid test %d passed\n", i);
214 for (i = 0; i <
ARRAY_SIZE(invalid_strings); ++i)
218 printf(
"invalid test %d failed\n", i);
222 printf(
"invalid test %d passed\n", i);
int UTF8_validateString(const char *string)
static const char * UTF8_char_validate(int len, const char *data)
struct @73 valid_ranges[]
int UTF8_validate(int len, const char *data)
int main(int argc, char **argv)