aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cstring/include/cstring.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/cstring/include/cstring.h b/cstring/include/cstring.h
index b07dad6..8ed4e93 100644
--- a/cstring/include/cstring.h
+++ b/cstring/include/cstring.h
@@ -43,6 +43,8 @@
43 } \ 43 } \
44 } \ 44 } \
45 \ 45 \
46 static inline STRING STRING##_make_empty() { return (STRING){0}; } \
47 \
46 static inline STRING STRING##_dirname(const STRING path) { \ 48 static inline STRING STRING##_dirname(const STRING path) { \
47 STRING str = path; \ 49 STRING str = path; \
48 for (int i = str.length - 1; i >= 0; --i) { \ 50 for (int i = str.length - 1; i >= 0; --i) { \
@@ -79,9 +81,8 @@
79 const STRING a, const char* b, const size_t b_length) { \ 81 const STRING a, const char* b, const size_t b_length) { \
80 ASSERT(a.length + b_length + 1 <= SIZE); \ 82 ASSERT(a.length + b_length + 1 <= SIZE); \
81 STRING str = {0}; \ 83 STRING str = {0}; \
82 strlcpy(str.str, a.str, SIZE); \ 84 STRING##_append_cstr_len(&str, a.str, a.length); \
83 strlcpy(str.str + a.length, b, SIZE - a.length); \ 85 STRING##_append_cstr_len(&str, b, b_length); \
84 str.length = a.length + b_length; \
85 return str; \ 86 return str; \
86 } \ 87 } \
87 \ 88 \
@@ -97,6 +98,15 @@
97 return STRING##_concat(STRING##_concat_cstr(a, "/"), b); \ 98 return STRING##_concat(STRING##_concat_cstr(a, "/"), b); \
98 } \ 99 } \
99 \ 100 \
101 static inline STRING STRING##_slice( \
102 const STRING a, const size_t start, const size_t end) { \
103 ASSERT(start < a.length); \
104 ASSERT(end <= a.length); \
105 STRING str = {0}; \
106 strlcpy(str.str, &a.str[start], end - start); \
107 return str; \
108 } \
109 \
100 static inline bool STRING##_eq_cstr_len( \ 110 static inline bool STRING##_eq_cstr_len( \
101 const STRING a, const char* b, size_t b_length) { \ 111 const STRING a, const char* b, size_t b_length) { \
102 return (a.length == b_length) && strncmp(a.str, b, a.length) == 0; \ 112 return (a.length == b_length) && strncmp(a.str, b, a.length) == 0; \