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() --- lib/mbstring/u8cut.c | 19 +++++++++++++++++++ lib/mbstring/u8split.c | 16 ---------------- 2 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 lib/mbstring/u8cut.c delete mode 100644 lib/mbstring/u8split.c (limited to 'lib') diff --git a/lib/mbstring/u8cut.c b/lib/mbstring/u8cut.c new file mode 100644 index 0000000..3dd9663 --- /dev/null +++ b/lib/mbstring/u8cut.c @@ -0,0 +1,19 @@ +#include "macros.h" +#include "mbstring.h" + +rune +u8cut(struct u8view *restrict x, struct u8view *restrict y, const rune *seps, + size_t n) +{ + ASSUME(y != nullptr); + ASSUME(seps != nullptr); + size_t off = u8cspn(*y, seps, n); + if (x != nullptr) { + x->p = y->p; + x->len = off; + } + VSHFT(y, off); + rune ch = MBEND; + u8next(&ch, y); + return ch; +} diff --git a/lib/mbstring/u8split.c b/lib/mbstring/u8split.c deleted file mode 100644 index c26f48b..0000000 --- a/lib/mbstring/u8split.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "mbstring.h" - -struct u8view -u8split(struct u8view *rhs, rune ch) -{ - struct u8view lhs = {.p = rhs->p}; - if ((rhs->p = u8chr(*rhs, ch)) == nullptr) { - lhs.len = rhs->len; - rhs->len = 0; - } else { - lhs.len = rhs->p - lhs.p; - rhs->len -= lhs.len; - u8next(nullptr, rhs); - } - return lhs; -} -- cgit v1.2.3