From 790aaa14406d45dd95dea3f7d6d00da5911c6584 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 4 May 2024 04:36:28 +0200 Subject: Replace u8split() with u8cut() --- test/_brk-test.h | 28 ++++++---------------------- test/_case-test.h | 6 +++--- 2 files changed, 9 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/_brk-test.h b/test/_brk-test.h index e468f23..3a66f23 100644 --- a/test/_brk-test.h +++ b/test/_brk-test.h @@ -19,7 +19,6 @@ #define CNTFUNC CONCAT(CONCAT(u8, BRKTYPE), cnt) static bool test(struct u8view, int); -static int hexdigits(rune); int main(int, char **argv) @@ -59,25 +58,21 @@ test(struct u8view sv, int id) typedef dynarr(char8_t) item; dynarr(item) items = {}; - struct u8view sv_cpy = sv; - - do { - rune op, ch; - u8next(&op, &sv_cpy); + rune op; + struct u8view sv_cpy = sv; + while ((op = u8cut(nullptr, &sv_cpy, U"×÷", 2)) != MBEND) { + rune ch; sscanf(sv_cpy.p, "%" SCNxRUNE, &ch); - int off = hexdigits(ch); - off = MAX(4, off); - VSHFT(&sv_cpy, off); - char8_t buf[U8_LEN_MAX] = {}; + char8_t buf[U8_LEN_MAX]; int w = rtou8(buf, sizeof(buf), ch); total += w; if (op == U'÷') DAPUSH(&items, (item){}); DAEXTEND(&items.buf[items.len - 1], buf, w); - } while (sv_cpy.len > 0); + } size_t off = 0; char8_t *p = bufalloc(nullptr, 1, total); @@ -114,14 +109,3 @@ test(struct u8view sv, int id) return true; } - -int -hexdigits(rune ch) -{ - int n = 0; - do { - ch /= 16; - n++; - } while (ch != 0); - return n; -} diff --git a/test/_case-test.h b/test/_case-test.h index 12e3a57..c594554 100644 --- a/test/_case-test.h +++ b/test/_case-test.h @@ -54,9 +54,9 @@ test(const char8_t *line, int id) { struct u8view sv = {line, strlen(line)}; struct u8view before, after, flags; - before = u8split(&sv, ';'); - after = u8split(&sv, ';'); - flags = u8split(&sv, ';'); + u8cut(&before, &sv, U";", 1); + u8cut(&after, &sv, U";", 1); + u8cut(&flags, &sv, U";", 1); enum caseflags cf = u8eq(flags, U8("ẞ")) ? CF_ẞ : u8eq(flags, U8("AZ")) ? CF_LANG_AZ -- cgit v1.2.3