diff options
author | Steven G. Johnson <stevenj@mit.edu> | 2015-05-29 21:58:21 -0400 |
---|---|---|
committer | Steven G. Johnson <stevenj@mit.edu> | 2015-05-29 21:58:21 -0400 |
commit | 35ec8e32e7e9ccbc7bc12da6eec5b11e72a9e674 (patch) | |
tree | 4652dafe789ee6a8ac76154dad6a7d14c2778df1 /test/tests.h | |
parent | 7c14ef5f8371e463a01e0f1de971caa600384390 (diff) | |
parent | 6a229a6776b154b1906b6a1f282b72b38322e36b (diff) | |
download | libutf8proc-35ec8e32e7e9ccbc7bc12da6eec5b11e72a9e674.tar.gz libutf8proc-35ec8e32e7e9ccbc7bc12da6eec5b11e72a9e674.tar.bz2 |
Merge pull request #35 from ScottPJones/spj/valid
Fix #34 handle 66 Unicode non-characters and surrogates correctly
Diffstat (limited to 'test/tests.h')
-rw-r--r-- | test/tests.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/test/tests.h b/test/tests.h index c27185d..6eb5457 100644 --- a/test/tests.h +++ b/test/tests.h @@ -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)); + } } |