diff options
| author | Tyge Lovset <[email protected]> | 2023-08-17 05:34:38 +0200 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2023-08-17 05:34:38 +0200 |
| commit | be0e64a9a19d3ca459284c61c497d141a78df1d7 (patch) | |
| tree | e2005e0a29d9e7386647ad9d92411635d01574c6 /include/stc/cstr.h | |
| parent | 2ba238e66efec7b6d895425c4f1160b3b72d242b (diff) | |
| download | STC-modified-be0e64a9a19d3ca459284c61c497d141a78df1d7.tar.gz STC-modified-be0e64a9a19d3ca459284c61c497d141a78df1d7.zip | |
Renamed "internal" csview member .str => .buf, as it is not null terminated like crawstr .str member.
Diffstat (limited to 'include/stc/cstr.h')
| -rw-r--r-- | include/stc/cstr.h | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/include/stc/cstr.h b/include/stc/cstr.h index bc147469..eeb65c39 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -98,7 +98,7 @@ STC_INLINE csview cstr_sv(const cstr* s) { : c_sv_2(s->sml.data, cstr_s_size(s)); } STC_INLINE crawstr cstr_rs(const cstr* s) - { csview sv = cstr_sv(s); return c_rs_2(sv.str, sv.size); } + { csview sv = cstr_sv(s); return c_rs_2(sv.buf, sv.size); } STC_INLINE cstr cstr_init(void) { return cstr_null; } @@ -113,7 +113,7 @@ STC_INLINE cstr cstr_from(const char* str) { return cstr_from_n(str, c_strlen(str)); } STC_INLINE cstr cstr_from_sv(csview sv) - { return cstr_from_n(sv.str, sv.size); } + { return cstr_from_n(sv.buf, sv.size); } STC_INLINE cstr cstr_from_rs(crawstr rs) { return cstr_from_n(rs.str, rs.size); } @@ -145,7 +145,7 @@ STC_INLINE cstr cstr_move(cstr* self) { STC_INLINE cstr cstr_clone(cstr s) { csview sv = cstr_sv(&s); - return cstr_from_n(sv.str, sv.size); + return cstr_from_n(sv.buf, sv.size); } STC_INLINE void cstr_drop(cstr* self) { @@ -201,8 +201,8 @@ STC_INLINE const char* cstr_u8_at(const cstr* self, intptr_t u8idx) STC_INLINE csview cstr_u8_chr(const cstr* self, intptr_t u8idx) { const char* str = cstr_str(self); csview sv; - sv.str = utf8_at(str, u8idx); - sv.size = utf8_chr_size(sv.str); + sv.buf = utf8_at(str, u8idx); + sv.size = utf8_chr_size(sv.buf); return sv; } @@ -211,7 +211,7 @@ STC_INLINE csview cstr_u8_chr(const cstr* self, intptr_t u8idx) { STC_INLINE cstr_iter cstr_begin(const cstr* self) { csview sv = cstr_sv(self); if (!sv.size) return c_LITERAL(cstr_iter){.ref = NULL}; - return c_LITERAL(cstr_iter){.u8 = {{sv.str, utf8_chr_size(sv.str)}}}; + return c_LITERAL(cstr_iter){.u8 = {{sv.buf, utf8_chr_size(sv.buf)}}}; } STC_INLINE cstr_iter cstr_end(const cstr* self) { (void)self; return c_LITERAL(cstr_iter){NULL}; @@ -242,7 +242,7 @@ STC_INLINE int cstr_icmp(const cstr* s1, const cstr* s2) 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 && !c_memcmp(x.str, y.str, x.size); + return x.size == y.size && !c_memcmp(x.buf, y.buf, x.size); } @@ -250,7 +250,7 @@ STC_INLINE bool cstr_equals(const cstr* self, const char* str) { return !strcmp(cstr_str(self), str); } STC_INLINE bool cstr_equals_sv(const cstr* self, csview sv) - { return sv.size == cstr_size(self) && !c_memcmp(cstr_str(self), sv.str, sv.size); } + { return sv.size == cstr_size(self) && !c_memcmp(cstr_str(self), sv.buf, sv.size); } STC_INLINE bool cstr_equals_s(const cstr* self, cstr s) { return !cstr_cmp(self, &s); } @@ -280,7 +280,7 @@ STC_INLINE bool cstr_contains_s(const cstr* self, cstr search) STC_INLINE bool cstr_starts_with_sv(const cstr* self, csview sub) { if (sub.size > cstr_size(self)) return false; - return !c_memcmp(cstr_str(self), sub.str, sub.size); + return !c_memcmp(cstr_str(self), sub.buf, sub.size); } STC_INLINE bool cstr_starts_with(const cstr* self, const char* sub) { @@ -302,7 +302,7 @@ STC_INLINE bool cstr_istarts_with(const cstr* self, const char* sub) { STC_INLINE bool cstr_ends_with_sv(const cstr* self, csview sub) { csview sv = cstr_sv(self); if (sub.size > sv.size) return false; - return !c_memcmp(sv.str + sv.size - sub.size, sub.str, sub.size); + return !c_memcmp(sv.buf + sv.size - sub.size, sub.buf, sub.size); } STC_INLINE bool cstr_ends_with_s(const cstr* self, cstr sub) @@ -314,7 +314,7 @@ STC_INLINE bool cstr_ends_with(const cstr* self, const char* sub) STC_INLINE bool cstr_iends_with(const cstr* self, const char* sub) { csview sv = cstr_sv(self); intptr_t n = c_strlen(sub); - return n <= sv.size && !utf8_icmp(sv.str + sv.size - n, sub); + return n <= sv.size && !utf8_icmp(sv.buf + sv.size - n, sub); } @@ -322,11 +322,11 @@ STC_INLINE char* cstr_assign(cstr* self, const char* str) { return cstr_assign_n(self, str, c_strlen(str)); } STC_INLINE char* cstr_assign_sv(cstr* self, csview sv) - { return cstr_assign_n(self, sv.str, sv.size); } + { return cstr_assign_n(self, sv.buf, sv.size); } STC_INLINE char* cstr_copy(cstr* self, cstr s) { csview sv = cstr_sv(&s); - return cstr_assign_n(self, sv.str, sv.size); + return cstr_assign_n(self, sv.buf, sv.size); } @@ -335,16 +335,16 @@ STC_INLINE char* cstr_push(cstr* self, const char* chr) STC_INLINE void cstr_pop(cstr* self) { csview sv = cstr_sv(self); - const char* s = sv.str + sv.size; + const char* s = sv.buf + sv.size; while ((*--s & 0xC0) == 0x80) ; - _cstr_set_size(self, (s - sv.str)); + _cstr_set_size(self, (s - sv.buf)); } STC_INLINE char* cstr_append(cstr* self, const char* str) { return cstr_append_n(self, str, c_strlen(str)); } STC_INLINE char* cstr_append_sv(cstr* self, csview sv) - { return cstr_append_n(self, sv.str, sv.size); } + { return cstr_append_n(self, sv.buf, sv.size); } STC_INLINE char* cstr_append_s(cstr* self, cstr s) { return cstr_append_sv(self, cstr_sv(&s)); } @@ -358,7 +358,7 @@ STC_INLINE void cstr_replace_4(cstr* self, const char* search, const char* repl, STC_INLINE void cstr_replace_at_sv(cstr* self, intptr_t pos, intptr_t len, const csview repl) { char* d = _cstr_internal_move(self, pos + len, pos + repl.size); - c_memcpy(d + pos, repl.str, repl.size); + c_memcpy(d + pos, repl.buf, repl.size); } STC_INLINE void cstr_replace_at(cstr* self, intptr_t pos, intptr_t len, const char* repl) @@ -400,12 +400,12 @@ fn_tocase[] = {{tolower, utf8_casefold}, static cstr cstr_tocase(csview sv, int k) { cstr out = cstr_init(); char *buf = cstr_reserve(&out, sv.size*3/2); - const char *end = sv.str + sv.size; + const char *end = sv.buf + sv.size; uint32_t cp; intptr_t sz = 0; utf8_decode_t d = {.state=0}; - while (sv.str < end) { - do { utf8_decode(&d, (uint8_t)*sv.str++); } while (d.state); + while (sv.buf < end) { + do { utf8_decode(&d, (uint8_t)*sv.buf++); } while (d.state); if (d.codep < 128) buf[sz++] = (char)fn_tocase[k].conv_asc((int)d.codep); else { @@ -450,13 +450,13 @@ bool cstr_valid_utf8(const cstr* self) STC_DEF uint64_t cstr_hash(const cstr *self) { csview sv = cstr_sv(self); - return cfasthash(sv.str, sv.size); + return cfasthash(sv.buf, sv.size); } STC_DEF intptr_t cstr_find_sv(const cstr* self, csview search) { csview sv = cstr_sv(self); - char* res = cstrnstrn(sv.str, search.str, sv.size, search.size); - return res ? (res - sv.str) : c_NPOS; + char* res = cstrnstrn(sv.buf, search.buf, sv.size, search.size); + return res ? (res - sv.buf) : c_NPOS; } STC_DEF char* _cstr_internal_move(cstr* self, const intptr_t pos1, const intptr_t pos2) { @@ -532,8 +532,8 @@ STC_DEF char* cstr_resize(cstr* self, const intptr_t size, const char value) { STC_DEF intptr_t cstr_find_at(const cstr* self, const intptr_t pos, const char* search) { csview sv = cstr_sv(self); if (pos > sv.size) return c_NPOS; - const char* res = strstr((char*)sv.str + pos, search); - return res ? (res - sv.str) : c_NPOS; + const char* res = strstr((char*)sv.buf + pos, search); + return res ? (res - sv.buf) : c_NPOS; } STC_DEF char* cstr_assign_n(cstr* self, const char* str, const intptr_t len) { @@ -588,13 +588,13 @@ STC_DEF cstr cstr_replace_sv(csview in, csview search, csview repl, int32_t coun intptr_t from = 0; char* res; if (!count) count = INT32_MAX; if (search.size) - while (count-- && (res = cstrnstrn(in.str + from, search.str, in.size - from, search.size))) { - const intptr_t pos = (res - in.str); - cstr_append_n(&out, in.str + from, pos - from); - cstr_append_n(&out, repl.str, repl.size); + while (count-- && (res = cstrnstrn(in.buf + from, search.buf, in.size - from, search.size))) { + const intptr_t pos = (res - in.buf); + cstr_append_n(&out, in.buf + from, pos - from); + cstr_append_n(&out, repl.buf, repl.size); from = pos + search.size; } - cstr_append_n(&out, in.str + from, in.size - from); + cstr_append_n(&out, in.buf + from, in.size - from); return out; } |
