summaryrefslogtreecommitdiff
path: root/include/al
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-02-02 23:00:02 -0500
committerAndrew Opalach <andrew@akon.city> 2024-02-02 23:00:02 -0500
commit4da4b06c8ae79370340a60ca83bd1f0206068ed3 (patch)
tree838397232e5e0cc09afa036a93ff9278d3997435 /include/al
parent3eeb6351ea365d8eb095a3db3063b6129f73a178 (diff)
downloadlibalabaster-4da4b06c8ae79370340a60ca83bd1f0206068ed3.tar.gz
libalabaster-4da4b06c8ae79370340a60ca83bd1f0206068ed3.tar.bz2
libalabaster-4da4b06c8ae79370340a60ca83bd1f0206068ed3.zip
Add some wstr functions
- al_wstr_c - al_wstr_cmp - al_wstr_rfind Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'include/al')
-rw-r--r--include/al/str.h2
-rw-r--r--include/al/wstr.h14
2 files changed, 15 insertions, 1 deletions
diff --git a/include/al/str.h b/include/al/str.h
index 9be1394..0ab7520 100644
--- a/include/al/str.h
+++ b/include/al/str.h
@@ -116,7 +116,7 @@ static inline s32 al_str_cmp(str *s, str *c, u32 start, u32 len)
if (start + len > s->len || len > c->len) {
return -1;
}
- return al_memcmp(s->data + start, c->data, len);
+ return al_memcmp(&al_str_at(s, start), c->data, len);
}
static inline bool al_str_eq(str *s, str *c)
diff --git a/include/al/wstr.h b/include/al/wstr.h
index 540ed55..2989ff9 100644
--- a/include/al/wstr.h
+++ b/include/al/wstr.h
@@ -18,6 +18,7 @@ typedef struct {
#define al_wstr_at(w, i) (w)->data[i]
#define al_wstr_atr(w, i) (w)->data[(w)->len + i]
+#define al_wstr_c(w) (&((wstr){ (u32)wcslen(w), 0, ((wchar_t *)(w)) }))
#define al_wstr_w(w, i, n) (&((wstr){ ((u32)(n)), 0, &al_wstr_at(w, i) }))
#define al_wstr_substr(w, start, end) al_wstr_w(w, start, ((end) - (start)))
@@ -86,6 +87,19 @@ static inline s32 al_wstr_width(wstr *w)
return wcswidth(w->data, w->len);
}
+static inline s32 al_wstr_cmp(wstr *w, wstr *c, u32 start, u32 len)
+{
+ return wcsncmp(&al_wstr_at(w, start), c->data, len);
+}
+
+static inline s32 al_wstr_rfind(wstr *w, wchar_t c)
+{
+ for (s32 i = w->len - 1; i >= 0; i--) {
+ if (al_wstr_at(w, i) == c) return i;
+ }
+ return -1;
+}
+
AL_UNUSED_FUNCTION_POP
#endif // _AL_WSTR_H