summaryrefslogtreecommitdiff
path: root/string32.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-22 23:55:03 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-22 23:55:03 -0500
commitdaf89b29a3ef37c272394cba3929290f2980a421 (patch)
tree866d05a76975111b35dd92997f54bc510f4d73d1 /string32.c
parent8da3cb956b14a7644f815a1874bdcf29a4cb711d (diff)
started auto-cd
Diffstat (limited to 'string32.c')
-rw-r--r--string32.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/string32.c b/string32.c
index 4d033c0..f678ad1 100644
--- a/string32.c
+++ b/string32.c
@@ -1,9 +1,18 @@
// UTF-32 string
typedef struct {
- size_t len;
char32_t *str;
+ size_t len;
} String32;
+String32 str32(char32_t *str, size_t len) {
+ String32 s = {str, len};
+ return s;
+}
+
+String32 str32_substr(String32 s, size_t from, size_t len) {
+ return str32(s.str + from, len);
+}
+
void str32_free(String32 *s) {
free(s->str);
s->str = NULL;
@@ -13,7 +22,7 @@ void str32_free(String32 *s) {
// the string returned should be str32_free'd.
// this will return an empty string if the allocation failed or the string is invalid UTF-8
String32 str32_from_utf8(char const *utf8) {
- String32 string = {0, NULL};
+ String32 string = {NULL, 0};
size_t len = strlen(utf8);
if (len) {
// the wide string uses at most as many "characters" (elements?) as the UTF-8 string