utf8proc

A clean C library for processing UTF-8 Unicode data
git clone https://git.sinitax.com/juliastrings/utf8proc
Log | Files | Refs | README | LICENSE | sfeed.txt

commit d588d7097c070c0fddd918573e562aa94e1fb26c
parent 0890a538bf8238cded9be0c81171f57e43f2c755
Author: Steven G. Johnson <stevenj@alum.mit.edu>
Date:   Sat, 28 Mar 2020 09:36:58 -0400

portable getline replacement (closes #182)

Diffstat:
Mtest/graphemetest.c | 5+++--
Mtest/normtest.c | 6+++---
Atest/simple_getline.h | 11+++++++++++
3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/test/graphemetest.c b/test/graphemetest.c @@ -1,15 +1,16 @@ #include "tests.h" +#include "simple_getline.h" int main(int argc, char **argv) { - char *buf = NULL; + char buf[8192]; 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) { + while (simple_getline(buf, f) > 0) { size_t bi = 0, si = 0; lineno += 1; diff --git a/test/normtest.c b/test/normtest.c @@ -1,4 +1,5 @@ #include "tests.h" +#include "simple_getline.h" #define CHECK_NORM(NRM, norm, src) { \ char *src_norm = (char*) utf8proc_ ## NRM((utf8proc_uint8_t*) src); \ @@ -9,13 +10,12 @@ int main(int argc, char **argv) { - char *buf = NULL; - size_t bufsize = 0; + char buf[8192]; FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL; char source[1024], NFC[1024], NFD[1024], NFKC[1024], NFKD[1024]; check(f != NULL, "error opening NormalizationTest.txt"); - while (getline(&buf, &bufsize, f) > 0) { + while (simple_getline(buf, f) > 0) { size_t offset; lineno += 1; diff --git a/test/simple_getline.h b/test/simple_getline.h @@ -0,0 +1,11 @@ +/* simplistic, portable replacement for getline, sufficient for our tests */ +static size_t simple_getline(char buf[8192], FILE *f) { + size_t i = 0; + while (i < 1023) { + int c = getc(f); + if (c == EOF || c == '\n') break; + buf[i++] = (char) c; + } + buf[i] = 0; + return i; +}