diff options
| author | Tyge Løvset <[email protected]> | 2022-08-08 21:20:57 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-08-08 21:20:57 +0200 |
| commit | 8e2f3b4aef0b5e8de66d02ca6268c13846cc05a0 (patch) | |
| tree | 928f33c35239fc6fd8beb1da0518bf619d3ef398 | |
| parent | c9e0c46d29db9c2a85154c9c6a75ce0d2e2180ff (diff) | |
| download | STC-modified-8e2f3b4aef0b5e8de66d02ca6268c13846cc05a0.tar.gz STC-modified-8e2f3b4aef0b5e8de66d02ca6268c13846cc05a0.zip | |
Final fix on icmp().
| -rw-r--r-- | include/stc/cstr.h | 2 | ||||
| -rw-r--r-- | include/stc/csview.h | 2 | ||||
| -rw-r--r-- | include/stc/utf8.h | 4 | ||||
| -rw-r--r-- | src/utf8code.c | 19 |
4 files changed, 8 insertions, 19 deletions
diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 0dabc044..3231c09d 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -303,7 +303,7 @@ STC_INLINE bool cstr_starts_with_s(cstr s, cstr sub) STC_INLINE bool cstr_istarts_with(cstr s, const char* sub) { csview sv = cstr_sv(&s); size_t len = strlen(sub); - return len <= sv.size && !utf8_icmp_sv(cstr_npos, sv, c_sv(sub, len)); + return len <= sv.size && !utf8_icmp_sv(sv, c_sv(sub, len)); } diff --git a/include/stc/csview.h b/include/stc/csview.h index cd19aed7..61ab4d6b 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -127,7 +127,7 @@ STC_INLINE int csview_cmp(const csview* x, const csview* y) { return strcmp(x->str, y->str); } STC_INLINE int csview_icmp(const csview* x, const csview* y) - { return utf8_icmp_sv(csview_npos, *x, *y); } + { return utf8_icmp_sv(*x, *y); } STC_INLINE bool csview_eq(const csview* x, const csview* y) { return x->size == y->size && !memcmp(x->str, y->str, x->size); } diff --git a/include/stc/utf8.h b/include/stc/utf8.h index 4b87bc0b..2dd51927 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -16,7 +16,7 @@ extern uint32_t utf8_casefold(uint32_t c); extern uint32_t utf8_tolower(uint32_t c); extern uint32_t utf8_toupper(uint32_t c); extern bool utf8_valid_n(const char* s, size_t nbytes); -extern int utf8_icmp_sv(size_t u8max, csview s1, csview s2); +extern int utf8_icmp_sv(csview s1, csview s2); extern unsigned utf8_encode(char *out, uint32_t c); extern uint32_t utf8_peek(const char *s, int u8pos); @@ -35,7 +35,7 @@ STC_INLINE uint32_t utf8_decode(utf8_decode_t* d, const uint32_t byte) { /* case-insensitive utf8 string comparison */ STC_INLINE int utf8_icmp(const char* s1, const char* s2) { - return utf8_icmp_sv(~(size_t)0, c_sv(s1, ~(size_t)0), c_sv(s2, ~(size_t)0)); + return utf8_icmp_sv(c_sv(s1, ~(size_t)0), c_sv(s2, ~(size_t)0)); } STC_INLINE bool utf8_valid(const char* s) { diff --git a/src/utf8code.c b/src/utf8code.c index 28c101fa..1790ad62 100644 --- a/src/utf8code.c +++ b/src/utf8code.c @@ -102,29 +102,18 @@ uint32_t utf8_toupper(uint32_t c) { } return c; } -/* -int utf8_icmp(const char* s1, const char* s2) { - utf8_decode_t d1 = {.state=0}, d2 = {.state=0}; - for (;;) { - do { utf8_decode(&d1, (uint8_t)*s1++); } while (d1.state); - do { utf8_decode(&d2, (uint8_t)*s2++); } while (d2.state); - int32_t c = utf8_casefold(d1.codep) - utf8_casefold(d2.codep); - if (c || !s2[-1]) - return c; - } -} -*/ -int utf8_icmp_sv(size_t u8max, const csview s1, const csview s2) { + +int utf8_icmp_sv(const csview s1, const csview s2) { utf8_decode_t d1 = {.state=0}, d2 = {.state=0}; size_t j1 = 0, j2 = 0; - while (u8max-- && ((j1 < s1.size) & (j2 < s2.size))) { + while ((j1 < s1.size) & (j2 < s2.size)) { do { utf8_decode(&d1, (uint8_t)s1.str[j1++]); } while (d1.state); do { utf8_decode(&d2, (uint8_t)s2.str[j2++]); } while (d2.state); int32_t c = utf8_casefold(d1.codep) - utf8_casefold(d2.codep); if (c || !s2.str[j2 - 1]) // OK if s1.size / s2.size are npos return c; } - return (j2 < s2.size) - (j1 < s1.size); + return 0; } bool utf8_isupper(uint32_t c) { |
