diff options
Diffstat (limited to 'normtest.c')
-rw-r--r-- | normtest.c | 45 |
1 files changed, 1 insertions, 44 deletions
@@ -1,47 +1,4 @@ -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> -#include <string.h> -#include <stdarg.h> - -#include "mojibake.h" - -size_t lineno = 0; - -void check(int cond, const char *format, ...) -{ - if (!cond) { - va_list args; - fprintf(stderr, "line %zd: ", lineno); - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); - fprintf(stderr, "\n"); - exit(1); - } -} - -/* if buf points to a sequence of codepoints encoded as hexadecimal strings, - 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 */ -size_t encode(char *dest, const char *buf) -{ - size_t i = 0, j, d = 0; - do { - int c; - while (isspace(buf[i])) ++i; /* skip whitespace */ - for (j=i; buf[j] && strchr("0123456789abcdef", tolower(buf[j])); ++j) - ; /* find end of hex input */ - if (j == i) { /* no codepoint found */ - dest[d] = 0; /* NUL-terminate destination string */ - return i + 1; - } - check(sscanf(buf + i, "%x", &c) == 1, "invalid hex input %s", buf+i); - i = j; /* skip to char after hex input */ - d += utf8proc_encode_char(c, (uint8_t *) (dest + d)); - } while (1); -} +#include "tests.h" #define CHECK_NORM(NRM, norm, src) { \ char *src_norm = (char*) utf8proc_ ## NRM((uint8_t*) src); \ |