diff options
| author | Tyge Lovset <[email protected]> | 2022-05-31 04:54:03 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2022-05-31 04:54:03 +0200 |
| commit | b09f435cf7fe7a8b4d976b921384c6176381cc7f (patch) | |
| tree | 7df61684e10afcfc433e7d7120faa000f8b0d400 /src/utf8code.c | |
| parent | 2688277a4efe011ffd35f0e3ce859bb110207d8e (diff) | |
| download | STC-modified-b09f435cf7fe7a8b4d976b921384c6176381cc7f.tar.gz STC-modified-b09f435cf7fe7a8b4d976b921384c6176381cc7f.zip | |
Generalized utf8_icmp_n() and added cstr_icmp(), csview_icmp().
Diffstat (limited to 'src/utf8code.c')
| -rw-r--r-- | src/utf8code.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/utf8code.c b/src/utf8code.c index cef3efca..2f429541 100644 --- a/src/utf8code.c +++ b/src/utf8code.c @@ -100,17 +100,19 @@ uint32_t utf8_toupper(uint32_t c) { return c; } -int utf8_icmp_n(const char* s1, const char* s2, size_t u8max) { +int utf8_icmp_n(size_t u8max, const char* s1, const size_t n1, + const char* s2, const size_t n2) { int ret = 0; utf8_decode_t d1 = {UTF8_OK}, d2 = {UTF8_OK}; - for (; u8max--; s1 += d1.size, s2 += d2.size) { - utf8_peek(&d1, s1); - utf8_peek(&d2, s2); + size_t j1 = 0, j2 = 0; + for (; u8max-- && ((j1 < n1) & (j2 < n2)); j1 += d1.size, j2 += d2.size) { + utf8_peek(&d1, s1+j1); + utf8_peek(&d2, s2+j2); ret = utf8_tolower(d1.codep) - utf8_tolower(d2.codep); - if (ret || !*s2) - break; + if (ret || !s2[j2]) + return ret; } - return ret; + return (j2 < n2) - (j1 < n1); } bool utf8_isupper(uint32_t c) { |
