summaryrefslogtreecommitdiff
path: root/test/tests.h
diff options
context:
space:
mode:
authorPeter Colberg <peter@colberg.org>2015-10-30 15:13:48 -0400
committerPeter Colberg <peter@colberg.org>2015-10-30 15:13:48 -0400
commit548497a3981ef671bfbd70c0cd3fe9b0d6261a6e (patch)
tree0f44dbde25b3cbfd5d880547d1bc56c0a644ef9d /test/tests.h
parent71230a08e490e6cae4d63297b1460503dba1e425 (diff)
downloadlibutf8proc-548497a3981ef671bfbd70c0cd3fe9b0d6261a6e.tar.gz
libutf8proc-548497a3981ef671bfbd70c0cd3fe9b0d6261a6e.tar.bz2
Move common test functions to separate module
This resolves warnings for missing function prototypes.
Diffstat (limited to 'test/tests.h')
-rw-r--r--test/tests.h46
1 files changed, 4 insertions, 42 deletions
diff --git a/test/tests.h b/test/tests.h
index 43df51f..4bc725a 100644
--- a/test/tests.h
+++ b/test/tests.h
@@ -8,46 +8,8 @@
#include "../utf8proc.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);
- }
-}
-
-size_t skipspaces(const char *buf, size_t i)
-{
- while (isspace(buf[i])) ++i;
- return i;
-}
-
-/* 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;
- for (;;) {
- int c;
- i = skipspaces(buf, i);
- 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", (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));
- }
-}
+extern size_t lineno;
+void check(int cond, const char *format, ...);
+size_t skipspaces(const char *buf, size_t i);
+size_t encode(char *dest, const char *buf);