Fix #34 handle 66 Unicode non-characters, also improve performance and surrogate handling
This commit is contained in:
committed by
ScottPJones
parent
7c14ef5f83
commit
6249e6b8b1
@@ -10,7 +10,7 @@ int my_isprint(int c) {
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int prevc, c, error = 0;
|
||||
int c, error = 0;
|
||||
|
||||
(void) argc; /* unused */
|
||||
(void) argv; /* unused */
|
||||
|
||||
@@ -6,6 +6,7 @@ int main(int argc, char **argv)
|
||||
size_t bufsize = 0;
|
||||
FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL;
|
||||
utf8proc_uint8_t src[1024];
|
||||
int len;
|
||||
|
||||
check(f != NULL, "error opening GraphemeBreakTest.txt");
|
||||
while (getline(&buf, &bufsize, f) > 0) {
|
||||
@@ -29,9 +30,10 @@ int main(int argc, char **argv)
|
||||
else if (buf[bi] == '#') { /* start of comments */
|
||||
break;
|
||||
}
|
||||
else { /* hex-encoded codepoint */
|
||||
bi += encode((char*) (src + si), buf + bi) - 1;
|
||||
else { /* hex-encoded codepoint */
|
||||
len = encode((char*) (src + si), buf + bi) - 1;
|
||||
while (src[si]) ++si; /* advance to NUL termination */
|
||||
bi += len;
|
||||
}
|
||||
}
|
||||
if (si && src[si-1] == '/')
|
||||
@@ -59,7 +61,7 @@ int main(int argc, char **argv)
|
||||
utf8proc_errmsg(glen));
|
||||
for (i = 0; i <= glen; ++i)
|
||||
if (g[i] == 0xff)
|
||||
g[i] = '/'; /* easier-to-read output (/ is not in test strings) */
|
||||
g[i] = '/'; /* easier-to-read output (/ is not in test strings) */
|
||||
check(!strcmp((char*)g, (char*)src),
|
||||
"grapheme mismatch: \"%s\" instead of \"%s\"", (char*)g, (char*)src);
|
||||
}
|
||||
|
||||
@@ -33,10 +33,11 @@ size_t skipspaces(const char *buf, size_t i)
|
||||
separated by whitespace, and terminated by any character not in
|
||||
[0-9a-fA-F] or whitespace, then stores the corresponding utf8 string
|
||||
in dest, returning the number of bytes read from buf */
|
||||
utf8proc_ssize_t unsafe_encode_char(utf8proc_int32_t uc, utf8proc_uint8_t *dst);
|
||||
size_t encode(char *dest, const char *buf)
|
||||
{
|
||||
size_t i = 0, j, d = 0;
|
||||
do {
|
||||
for (;;) {
|
||||
int c;
|
||||
i = skipspaces(buf, i);
|
||||
for (j=i; buf[j] && strchr("0123456789abcdef", tolower(buf[j])); ++j)
|
||||
@@ -45,9 +46,9 @@ size_t encode(char *dest, const char *buf)
|
||||
dest[d] = 0; /* NUL-terminate destination string */
|
||||
return i + 1;
|
||||
}
|
||||
check(sscanf(buf + i, "%x", &c) == 1, "invalid hex input %s", buf+i);
|
||||
check(sscanf(buf + i, "%x", (unsigned int *)&c) == 1, "invalid hex input %s", buf+i);
|
||||
i = j; /* skip to char after hex input */
|
||||
d += utf8proc_encode_char(c, (utf8proc_uint8_t *) (dest + d));
|
||||
} while (1);
|
||||
d += unsafe_encode_char(c, (utf8proc_uint8_t *) (dest + d));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user