summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/stc/cstr.h5
-rw-r--r--include/stc/csview.h3
-rw-r--r--include/stc/utf8.h5
3 files changed, 11 insertions, 2 deletions
diff --git a/include/stc/cstr.h b/include/stc/cstr.h
index 273ad70b..7bbd9f3b 100644
--- a/include/stc/cstr.h
+++ b/include/stc/cstr.h
@@ -240,6 +240,11 @@ STC_INLINE char* cstr_expand_uninit(cstr *self, size_t n) {
STC_INLINE int cstr_cmp(const cstr* s1, const cstr* s2)
{ return strcmp(cstr_str(s1), cstr_str(s2)); }
+STC_INLINE int cstr_icmp(const cstr* s1, const cstr* s2) {
+ csview x = cstr_sv(s1), y = cstr_sv(s2);
+ return utf8_icmp_n(~(size_t)0, x.str, x.size, y.str, y.size);
+}
+
STC_INLINE bool cstr_eq(const cstr* s1, const cstr* s2) {
csview x = cstr_sv(s1), y = cstr_sv(s2);
return x.size == y.size && !memcmp(x.str, y.str, x.size);
diff --git a/include/stc/csview.h b/include/stc/csview.h
index eebcb9b7..8508db4f 100644
--- a/include/stc/csview.h
+++ b/include/stc/csview.h
@@ -165,6 +165,9 @@ STC_INLINE bool cstr_ends_with_sv(cstr s, csview sub) {
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_n(~(size_t)0, x->str, x->size, y->str, y->size); }
+
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 333a0f92..a3647e3c 100644
--- a/include/stc/utf8.h
+++ b/include/stc/utf8.h
@@ -38,7 +38,8 @@ uint32_t utf8_toupper(uint32_t c);
bool utf8_valid(const char* s);
bool utf8_valid_n(const char* s, size_t n);
-int utf8_icmp_n(const char* s1, const char* s2, size_t u8max);
+int utf8_icmp_n(size_t u8max, const char* s1, size_t n1,
+ const char* s2, size_t n2);
/* encode/decode next utf8 codepoint. */
enum { UTF8_OK = 0, UTF8_ERROR = 4 };
@@ -50,7 +51,7 @@ void utf8_decode(utf8_decode_t *d, const uint8_t b);
/* case-insensitive utf8 string comparison */
STC_INLINE int utf8_icmp(const char* s1, const char* s2)
- { return utf8_icmp_n(s1, s2, (size_t)(-1)); }
+ { return utf8_icmp_n(~(size_t)0, s1, ~(size_t)0, s2, ~(size_t)0); }
/* number of characters in the utf8 codepoint from s */
STC_INLINE unsigned utf8_codep_size(const char *s) {