diff options
| author | Tyge Løvset <[email protected]> | 2022-08-09 02:09:51 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-08-09 02:09:51 +0200 |
| commit | 0861b814130ab77b0e228e6f41a8c898959d69f1 (patch) | |
| tree | 5dc7842ad35515a09eda3c4f64d7caf777e1cc84 | |
| parent | 919bd0757fd11c67371e92d8d272b59731316251 (diff) | |
| download | STC-modified-0861b814130ab77b0e228e6f41a8c898959d69f1.tar.gz STC-modified-0861b814130ab77b0e228e6f41a8c898959d69f1.zip | |
Two more fixes on csview comparison.
| -rw-r--r-- | include/stc/csview.h | 7 | ||||
| -rw-r--r-- | src/utf8code.c | 4 |
2 files changed, 7 insertions, 4 deletions
diff --git a/include/stc/csview.h b/include/stc/csview.h index 61ab4d6b..2efeff5b 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -123,8 +123,11 @@ STC_INLINE csview cstr_u8_slice(const cstr* self , size_t u8p1, size_t u8p2) #endif /* ---- Container helper functions ---- */ -STC_INLINE int csview_cmp(const csview* x, const csview* y) - { return strcmp(x->str, y->str); } +STC_INLINE int csview_cmp(const csview* x, const csview* y) { + size_t n = x->size < y->size ? x->size : y->size; + int c = memcmp(x->str, y->str, n); + return c ? c : x->size - y->size; +} STC_INLINE int csview_icmp(const csview* x, const csview* y) { return utf8_icmp_sv(*x, *y); } diff --git a/src/utf8code.c b/src/utf8code.c index 1790ad62..ebd434ea 100644 --- a/src/utf8code.c +++ b/src/utf8code.c @@ -110,10 +110,10 @@ int utf8_icmp_sv(const csview s1, const csview s2) { 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 + if (c || !s2.str[j2 - 1]) // OK if s1.size and s2.size are npos return c; } - return 0; + return s1.size - s2.size; } bool utf8_isupper(uint32_t c) { |
