summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-04-17 09:43:52 -0400
committerAndrew Opalach <andrew@akon.city> 2025-04-17 09:43:52 -0400
commite5df584d6d8dc8c9036210943e42e43b30ac3def (patch)
tree4896c46999ef78d11d1a0874e029cb887bb50089 /include
parentf6a8686b2c209b0e25cd64a587d6e9fb55200ec4 (diff)
downloadlibalabaster-e5df584d6d8dc8c9036210943e42e43b30ac3def.tar.gz
libalabaster-e5df584d6d8dc8c9036210943e42e43b30ac3def.tar.bz2
libalabaster-e5df584d6d8dc8c9036210943e42e43b30ac3def.zip
(w)str: Consistency between cmp() and eq()
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'include')
-rw-r--r--include/al/str.h6
-rw-r--r--include/al/wstr.h7
2 files changed, 10 insertions, 3 deletions
diff --git a/include/al/str.h b/include/al/str.h
index d7dab1c..4ff936b 100644
--- a/include/al/str.h
+++ b/include/al/str.h
@@ -103,11 +103,11 @@ static inline void al_str_prepend(str *s, str *c)
al_str_insert(s, 0, c);
}
-static inline s32 al_str_cmp(str *s, str *c, u32 i, u32 length)
+static inline s32 al_str_cmp(str *s, str *c, u32 start, u32 length)
{
if (length > c->length) return 1;
- else if (length + i > s->length) return -1;
- return al_memcmp(&al_str_at(s, i), c->data, length);
+ else if (length + start > s->length) return -1;
+ return al_memcmp(&al_str_at(s, start), c->data, length);
}
static inline bool al_str_eq(str *s, str *c)
diff --git a/include/al/wstr.h b/include/al/wstr.h
index 5d5f6ac..efecbfe 100644
--- a/include/al/wstr.h
+++ b/include/al/wstr.h
@@ -170,6 +170,8 @@ static inline s32 al_wstr_width(wstr *w)
static inline s32 al_wstr_cmp(wstr *w, wstr *c, u32 start, u32 length)
{
#ifdef AL_HAVE_WIDE_STRING
+ if (length > c->length) return 1;
+ else if (length + start > w->length) return -1;
return wcsncmp(&al_wstr_at(w, start), c->data, length);
#else
(void)w;
@@ -180,6 +182,11 @@ static inline s32 al_wstr_cmp(wstr *w, wstr *c, u32 start, u32 length)
#endif
}
+static inline bool al_wstr_eq(wstr *w, wstr *c)
+{
+ return al_wstr_cmp(w, c, 0, MAX(w->length, c->length)) == 0;
+}
+
static inline u32 al_wstr_find(wstr *w, wchar_t c)
{
for (u32 i = 0; i < w->length; i++) {