diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-05-04 04:36:28 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-05-04 04:44:41 +0200 |
commit | 790aaa14406d45dd95dea3f7d6d00da5911c6584 (patch) | |
tree | f6e458cc3cde881893c06cba6cee94325c582112 /test | |
parent | 8f7f007a52f39c1e03817d417e95877526945b45 (diff) |
Replace u8split() with u8cut()
Diffstat (limited to 'test')
-rw-r--r-- | test/_brk-test.h | 28 | ||||
-rw-r--r-- | test/_case-test.h | 6 |
2 files changed, 9 insertions, 25 deletions
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 |