diff options
| author | Tyge Løvset <[email protected]> | 2023-01-31 18:55:08 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-31 18:55:08 +0100 |
| commit | b677a0c3950b8294ba6458e682a885351273ac08 (patch) | |
| tree | f309f7f7571fb588f0f65254d17fa09d678a8e3c /include/stc/cstr.h | |
| parent | a24ecd6bbfffc2e0b75b8ed48fcb5306d367ad3e (diff) | |
| download | STC-modified-b677a0c3950b8294ba6458e682a885351273ac08.tar.gz STC-modified-b677a0c3950b8294ba6458e682a885351273ac08.zip | |
Converted all containers but the maps and examples to signed sizes and indices.
Diffstat (limited to 'include/stc/cstr.h')
| -rw-r--r-- | include/stc/cstr.h | 212 |
1 files changed, 106 insertions, 106 deletions
diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 9f6415ac..f965487c 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -47,26 +47,26 @@ #endif enum { cstr_s_cap = sizeof(cstr_buf) - 2 }; -#define cstr_s_size(s) ((size_t)(s)->sml.size) +#define cstr_s_size(s) ((intptr_t)(s)->sml.size) #define cstr_s_set_size(s, len) ((s)->sml.size = (uint8_t)(len), (s)->sml.data[len] = 0) #define cstr_s_data(s) (s)->sml.data #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define byte_rotl_(x, b) ((x) << (b)*8 | (x) >> (sizeof(x) - (b))*8) - #define cstr_l_cap(s) (~byte_rotl_((s)->lon.ncap, sizeof((s)->lon.ncap) - 1)) - #define cstr_l_set_cap(s, cap) ((s)->lon.ncap = ~byte_rotl_(cap, 1)) + #define cstr_l_cap(s) (intptr_t)(~byte_rotl_((s)->lon.ncap, sizeof((s)->lon.ncap) - 1)) + #define cstr_l_set_cap(s, cap) ((s)->lon.ncap = ~byte_rotl_((size_t)(cap), 1)) #else - #define cstr_l_cap(s) (~(s)->lon.ncap) - #define cstr_l_set_cap(s, cap) ((s)->lon.ncap = ~(cap)) + #define cstr_l_cap(s) (intptr_t)(~(s)->lon.ncap) + #define cstr_l_set_cap(s, cap) ((s)->lon.ncap = ~(size_t)(cap)) #endif -#define cstr_l_size(s) ((s)->lon.size) -#define cstr_l_set_size(s, len) ((s)->lon.data[(s)->lon.size = (len)] = 0) +#define cstr_l_size(s) (intptr_t)((s)->lon.size) +#define cstr_l_set_size(s, len) ((s)->lon.data[(s)->lon.size = (size_t)(len)] = 0) #define cstr_l_data(s) (s)->lon.data #define cstr_l_drop(s) c_free((s)->lon.data) #define cstr_is_long(s) ((s)->sml.size > 127) -STC_API char* _cstr_init(cstr* self, size_t len, size_t cap); -STC_API char* _cstr_internal_move(cstr* self, size_t pos1, size_t pos2); +STC_API char* _cstr_init(cstr* self, intptr_t len, intptr_t cap); +STC_API char* _cstr_internal_move(cstr* self, intptr_t pos1, intptr_t pos2); /**************************** PUBLIC API **********************************/ @@ -74,19 +74,19 @@ STC_API char* _cstr_internal_move(cstr* self, size_t pos1, size_t pos2); #define cstr_NULL (c_LITERAL(cstr){{{0}, 0}}) #define cstr_toraw(self) cstr_str(self) -STC_API char* cstr_reserve(cstr* self, size_t cap); -STC_API void cstr_shrink_to_fit(cstr* self); -STC_API void cstr_resize(cstr* self, size_t size, char value); -STC_API size_t cstr_find_at(const cstr* self, size_t pos, const char* search); -STC_API char* cstr_assign_n(cstr* self, const char* str, size_t len); -STC_API char* cstr_append_n(cstr* self, const char* str, size_t len); -STC_API bool cstr_getdelim(cstr *self, int delim, FILE *fp); -STC_API void cstr_erase(cstr* self, size_t pos, size_t len); -STC_API void cstr_u8_erase(cstr* self, size_t bytepos, size_t u8len); -STC_API cstr cstr_from_fmt(const char* fmt, ...); -STC_API size_t cstr_append_fmt(cstr* self, const char* fmt, ...); -STC_API size_t cstr_printf(cstr* self, const char* fmt, ...); -STC_API cstr cstr_replace_sv(csview sv, csview search, csview repl, unsigned count); +STC_API char* cstr_reserve(cstr* self, intptr_t cap); +STC_API void cstr_shrink_to_fit(cstr* self); +STC_API void cstr_resize(cstr* self, intptr_t size, char value); +STC_API intptr_t cstr_find_at(const cstr* self, intptr_t pos, const char* search); +STC_API char* cstr_assign_n(cstr* self, const char* str, intptr_t len); +STC_API char* cstr_append_n(cstr* self, const char* str, intptr_t len); +STC_API bool cstr_getdelim(cstr *self, int delim, FILE *fp); +STC_API void cstr_erase(cstr* self, intptr_t pos, intptr_t len); +STC_API void cstr_u8_erase(cstr* self, intptr_t bytepos, intptr_t u8len); +STC_API cstr cstr_from_fmt(const char* fmt, ...); +STC_API intptr_t cstr_append_fmt(cstr* self, const char* fmt, ...); +STC_API intptr_t cstr_printf(cstr* self, const char* fmt, ...); +STC_API cstr cstr_replace_sv(csview sv, csview search, csview repl, int32_t count); STC_INLINE cstr_buf cstr_buffer(cstr* s) { return cstr_is_long(s) @@ -101,25 +101,25 @@ STC_INLINE csview cstr_sv(const cstr* s) { STC_INLINE cstr cstr_init(void) { return cstr_NULL; } -STC_INLINE cstr cstr_from_n(const char* str, const size_t len) { +STC_INLINE cstr cstr_from_n(const char* str, const intptr_t len) { cstr s; - memcpy(_cstr_init(&s, len, len), str, len); + c_memcpy(_cstr_init(&s, len, len), str, len); return s; } STC_INLINE cstr cstr_from(const char* str) - { return cstr_from_n(str, strlen(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); } -STC_INLINE cstr cstr_with_size(const size_t size, const char value) { +STC_INLINE cstr cstr_with_size(const intptr_t size, const char value) { cstr s; - memset(_cstr_init(&s, size, size), value, size); + c_memset(_cstr_init(&s, size, size), value, size); return s; } -STC_INLINE cstr cstr_with_capacity(const size_t cap) { +STC_INLINE cstr cstr_with_capacity(const intptr_t cap) { cstr s; _cstr_init(&s, 0, cap); return s; @@ -150,7 +150,7 @@ STC_INLINE void cstr_drop(cstr* self) { #define SSO_CALL(s, call) (cstr_is_long(s) ? cstr_l_##call : cstr_s_##call) -STC_INLINE void _cstr_set_size(cstr* self, size_t len) +STC_INLINE void _cstr_set_size(cstr* self, intptr_t len) { SSO_CALL(self, set_size(self, len)); } STC_INLINE char* cstr_data(cstr* self) @@ -162,10 +162,10 @@ STC_INLINE const char* cstr_str(const cstr* self) STC_INLINE bool cstr_empty(const cstr* self) { return self->sml.size == 0; } -STC_INLINE size_t cstr_size(const cstr* self) +STC_INLINE intptr_t cstr_size(const cstr* self) { return SSO_CALL(self, size(self)); } -STC_INLINE size_t cstr_capacity(const cstr* self) +STC_INLINE intptr_t cstr_capacity(const cstr* self) { return cstr_is_long(self) ? cstr_l_cap(self) : cstr_s_cap; } // utf8 methods defined in/depending on src/utf8code.c: @@ -182,10 +182,10 @@ STC_INLINE cstr cstr_toupper_sv(csview sv) { return cstr_tocase(sv, 2); } STC_INLINE cstr cstr_tolower(const char* str) - { return cstr_tolower_sv(c_SV(str, strlen(str))); } + { return cstr_tolower_sv(c_SV(str, c_strlen(str))); } STC_INLINE cstr cstr_toupper(const char* str) - { return cstr_toupper_sv(c_SV(str, strlen(str))); } + { return cstr_toupper_sv(c_SV(str, c_strlen(str))); } STC_INLINE void cstr_lowercase(cstr* self) { cstr_take(self, cstr_tolower_sv(cstr_sv(self))); } @@ -198,19 +198,19 @@ STC_INLINE bool cstr_valid_utf8(const cstr* self) // other utf8 -STC_INLINE size_t cstr_u8_size(const cstr* self) +STC_INLINE intptr_t cstr_u8_size(const cstr* self) { return utf8_size(cstr_str(self)); } -STC_INLINE size_t cstr_u8_size_n(const cstr* self, size_t nbytes) +STC_INLINE intptr_t cstr_u8_size_n(const cstr* self, intptr_t nbytes) { return utf8_size_n(cstr_str(self), nbytes); } -STC_INLINE size_t cstr_u8_to_pos(const cstr* self, size_t u8idx) +STC_INLINE intptr_t cstr_u8_to_pos(const cstr* self, intptr_t u8idx) { return utf8_pos(cstr_str(self), u8idx); } -STC_INLINE const char* cstr_u8_at(const cstr* self, size_t u8idx) +STC_INLINE const char* cstr_u8_at(const cstr* self, intptr_t u8idx) { return utf8_at(cstr_str(self), u8idx); } -STC_INLINE csview cstr_u8_chr(const cstr* self, size_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); @@ -246,8 +246,8 @@ STC_INLINE cstr_iter cstr_advance(cstr_iter it, intptr_t pos) { STC_INLINE void cstr_clear(cstr* self) { _cstr_set_size(self, 0); } -STC_INLINE char* cstr_append_uninit(cstr *self, size_t len) { - size_t sz = cstr_size(self); +STC_INLINE char* cstr_append_uninit(cstr *self, intptr_t len) { + intptr_t sz = cstr_size(self); char* d = cstr_reserve(self, sz + len); if (!d) return NULL; _cstr_set_size(self, sz + len); @@ -262,7 +262,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 && !memcmp(x.str, y.str, x.size); + return x.size == y.size && !c_memcmp(x.str, y.str, x.size); } @@ -270,7 +270,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) && !memcmp(cstr_str(self), sv.str, sv.size); } + { return sv.size == cstr_size(self) && !c_memcmp(cstr_str(self), sv.str, sv.size); } STC_INLINE bool cstr_equals_s(const cstr* self, cstr s) { return !cstr_cmp(self, &s); } @@ -279,14 +279,14 @@ STC_INLINE bool cstr_iequals(const cstr* self, const char* str) { return !utf8_icmp(cstr_str(self), str); } -STC_INLINE size_t cstr_find(const cstr* self, const char* search) { +STC_INLINE intptr_t cstr_find(const cstr* self, const char* search) { const char *str = cstr_str(self), *res = strstr((char*)str, search); - return res ? (size_t)(res - str) : c_NPOS; + return res ? (res - str) : c_NPOS; } -STC_API size_t cstr_find_sv(const cstr* self, csview search); +STC_API intptr_t cstr_find_sv(const cstr* self, csview search); -STC_INLINE size_t cstr_find_s(const cstr* self, cstr search) +STC_INLINE intptr_t cstr_find_s(const cstr* self, cstr search) { return cstr_find(self, cstr_str(&search)); } @@ -302,7 +302,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 !memcmp(cstr_str(self), sub.str, sub.size); + return !c_memcmp(cstr_str(self), sub.str, sub.size); } STC_INLINE bool cstr_starts_with(const cstr* self, const char* sub) { @@ -316,7 +316,7 @@ STC_INLINE bool cstr_starts_with_s(const cstr* self, cstr sub) STC_INLINE bool cstr_istarts_with(const cstr* self, const char* sub) { csview sv = cstr_sv(self); - size_t len = strlen(sub); + intptr_t len = c_strlen(sub); return len <= sv.size && !utf8_icmp_sv(sv, c_SV(sub, len)); } @@ -324,24 +324,24 @@ 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 !memcmp(sv.str + sv.size - sub.size, sub.str, sub.size); + return !c_memcmp(sv.str + sv.size - sub.size, sub.str, sub.size); } STC_INLINE bool cstr_ends_with_s(const cstr* self, cstr sub) { return cstr_ends_with_sv(self, cstr_sv(&sub)); } STC_INLINE bool cstr_ends_with(const cstr* self, const char* sub) - { return cstr_ends_with_sv(self, c_SV(sub, strlen(sub))); } + { return cstr_ends_with_sv(self, c_SV(sub, c_strlen(sub))); } STC_INLINE bool cstr_iends_with(const cstr* self, const char* sub) { csview sv = cstr_sv(self); - size_t n = strlen(sub); + intptr_t n = c_strlen(sub); return n <= sv.size && !utf8_icmp(sv.str + sv.size - n, sub); } STC_INLINE char* cstr_assign(cstr* self, const char* str) - { return cstr_assign_n(self, str, strlen(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); } @@ -359,11 +359,11 @@ STC_INLINE void cstr_pop(cstr* self) { csview sv = cstr_sv(self); const char* s = sv.str + sv.size; while ((*--s & 0xC0) == 0x80) ; - _cstr_set_size(self, (size_t)(s - sv.str)); + _cstr_set_size(self, (s - sv.str)); } STC_INLINE char* cstr_append(cstr* self, const char* str) - { return cstr_append_n(self, str, strlen(str)); } + { return cstr_append_n(self, str, c_strlen(str)); } STC_INLINE void cstr_append_sv(cstr* self, csview sv) { cstr_append_n(self, sv.str, sv.size); } @@ -375,33 +375,33 @@ STC_INLINE char* cstr_append_s(cstr* self, cstr s) { #define cstr_replace(...) c_MACRO_OVERLOAD(cstr_replace, __VA_ARGS__) #define cstr_replace_3(self, search, repl) cstr_replace_4(self, search, repl, ~0U) -STC_INLINE void cstr_replace_4(cstr* self, const char* search, const char* repl, unsigned count) { - cstr_take(self, cstr_replace_sv(cstr_sv(self), c_SV(search, strlen(search)), - c_SV(repl, strlen(repl)), count)); +STC_INLINE void cstr_replace_4(cstr* self, const char* search, const char* repl, int32_t count) { + cstr_take(self, cstr_replace_sv(cstr_sv(self), c_SV(search, c_strlen(search)), + c_SV(repl, c_strlen(repl)), count)); } -STC_INLINE void cstr_replace_at_sv(cstr* self, size_t pos, size_t len, const csview 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); - memcpy(d + pos, repl.str, repl.size); + c_memcpy(d + pos, repl.str, repl.size); } -STC_INLINE void cstr_replace_at(cstr* self, size_t pos, size_t len, const char* repl) - { cstr_replace_at_sv(self, pos, len, c_SV(repl, strlen(repl))); } +STC_INLINE void cstr_replace_at(cstr* self, intptr_t pos, intptr_t len, const char* repl) + { cstr_replace_at_sv(self, pos, len, c_SV(repl, c_strlen(repl))); } -STC_INLINE void cstr_replace_at_s(cstr* self, size_t pos, size_t len, cstr repl) +STC_INLINE void cstr_replace_at_s(cstr* self, intptr_t pos, intptr_t len, cstr repl) { cstr_replace_at_sv(self, pos, len, cstr_sv(&repl)); } -STC_INLINE void cstr_u8_replace_at(cstr* self, size_t bytepos, size_t u8len, csview repl) +STC_INLINE void cstr_u8_replace_at(cstr* self, intptr_t bytepos, intptr_t u8len, csview repl) { cstr_replace_at_sv(self, bytepos, utf8_pos(cstr_str(self) + bytepos, u8len), repl); } -STC_INLINE void cstr_insert(cstr* self, size_t pos, const char* str) - { cstr_replace_at_sv(self, pos, 0, c_SV(str, strlen(str))); } +STC_INLINE void cstr_insert(cstr* self, intptr_t pos, const char* str) + { cstr_replace_at_sv(self, pos, 0, c_SV(str, c_strlen(str))); } -STC_INLINE void cstr_insert_sv(cstr* self, size_t pos, csview sv) +STC_INLINE void cstr_insert_sv(cstr* self, intptr_t pos, csview sv) { cstr_replace_at_sv(self, pos, 0, sv); } -STC_INLINE void cstr_insert_s(cstr* self, size_t pos, cstr s) { +STC_INLINE void cstr_insert_s(cstr* self, intptr_t pos, cstr s) { csview sv = cstr_sv(&s); cstr_replace_at_sv(self, pos, 0, sv); } @@ -425,7 +425,7 @@ 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; - uint32_t cp; size_t sz = 0; + uint32_t cp; intptr_t sz = 0; utf8_decode_t d = {.state=0}; while (sv.str < end) { @@ -451,25 +451,25 @@ STC_DEF uint64_t cstr_hash(const cstr *self) { return cfasthash(sv.str, sv.size); } -STC_DEF size_t cstr_find_sv(const cstr* self, csview search) { +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 ? (size_t)(res - sv.str) : c_NPOS; + return res ? (res - sv.str) : c_NPOS; } -STC_DEF char* _cstr_internal_move(cstr* self, const size_t pos1, const size_t pos2) { +STC_DEF char* _cstr_internal_move(cstr* self, const intptr_t pos1, const intptr_t pos2) { cstr_buf r = cstr_buffer(self); if (pos1 != pos2) { - const intptr_t newlen = (intptr_t)(r.size + pos2 - pos1); - if (newlen > (intptr_t)r.cap) + const intptr_t newlen = (r.size + pos2 - pos1); + if (newlen > r.cap) r.data = cstr_reserve(self, r.size*3/2 + pos2 - pos1); - memmove(&r.data[pos2], &r.data[pos1], r.size - pos1); - _cstr_set_size(self, (size_t)newlen); + c_memmove(&r.data[pos2], &r.data[pos1], r.size - pos1); + _cstr_set_size(self, newlen); } return r.data; } -STC_DEF char* _cstr_init(cstr* self, const size_t len, const size_t cap) { +STC_DEF char* _cstr_init(cstr* self, const intptr_t len, const intptr_t cap) { if (cap > cstr_s_cap) { self->lon.data = (char *)c_malloc(cap + 1); cstr_l_set_size(self, len); @@ -488,13 +488,13 @@ STC_DEF void cstr_shrink_to_fit(cstr* self) { self->lon.data = (char *)c_realloc(self->lon.data, r.size + 1); cstr_l_set_cap(self, r.size); } else if (r.cap > cstr_s_cap) { - memcpy(self->sml.data, r.data, r.size + 1); + c_memcpy(self->sml.data, r.data, r.size + 1); cstr_s_set_size(self, r.size); c_free(r.data); } } -STC_DEF char* cstr_reserve(cstr* self, const size_t cap) { +STC_DEF char* cstr_reserve(cstr* self, const intptr_t cap) { if (cstr_is_long(self)) { if (cap > cstr_l_cap(self)) { self->lon.data = (char *)c_realloc(self->lon.data, cap + 1); @@ -505,47 +505,47 @@ STC_DEF char* cstr_reserve(cstr* self, const size_t cap) { /* from short to long: */ if (cap > cstr_s_cap) { char* data = (char *)c_malloc(cap + 1); - const size_t len = cstr_s_size(self); - memcpy(data, self->sml.data, cstr_s_cap + 1); + const intptr_t len = cstr_s_size(self); + c_memcpy(data, self->sml.data, cstr_s_cap + 1); self->lon.data = data; - self->lon.size = len; + self->lon.size = (size_t)len; cstr_l_set_cap(self, cap); return data; } return self->sml.data; } -STC_DEF void cstr_resize(cstr* self, const size_t size, const char value) { +STC_DEF void cstr_resize(cstr* self, const intptr_t size, const char value) { cstr_buf r = cstr_buffer(self); if (size > r.size) { if (size > r.cap) r.data = cstr_reserve(self, size); - memset(r.data + r.size, value, size - r.size); + c_memset(r.data + r.size, value, size - r.size); } _cstr_set_size(self, size); } -STC_DEF size_t cstr_find_at(const cstr* self, const size_t pos, const char* search) { +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 ? (size_t)(res - sv.str) : c_NPOS; + return res ? (res - sv.str) : c_NPOS; } -STC_DEF char* cstr_assign_n(cstr* self, const char* str, const size_t len) { +STC_DEF char* cstr_assign_n(cstr* self, const char* str, const intptr_t len) { char* d = cstr_reserve(self, len); - memmove(d, str, len); + c_memmove(d, str, len); _cstr_set_size(self, len); return d; } -STC_DEF char* cstr_append_n(cstr* self, const char* str, const size_t len) { +STC_DEF char* cstr_append_n(cstr* self, const char* str, const intptr_t len) { cstr_buf r = cstr_buffer(self); if (r.size + len > r.cap) { const size_t off = (size_t)(str - r.data); r.data = cstr_reserve(self, r.size*3/2 + len); - if (off <= r.size) str = r.data + off; /* handle self append */ + if (off <= (size_t)r.size) str = r.data + off; /* handle self append */ } - memcpy(r.data + r.size, str, len); + c_memcpy(r.data + r.size, str, len); _cstr_set_size(self, r.size + len); return r.data; } @@ -554,7 +554,7 @@ STC_DEF bool cstr_getdelim(cstr *self, const int delim, FILE *fp) { int c = fgetc(fp); if (c == EOF) return false; - size_t pos = 0; + intptr_t pos = 0; cstr_buf r = cstr_buffer(self); for (;;) { if (c == delim || c == EOF) { @@ -571,13 +571,13 @@ STC_DEF bool cstr_getdelim(cstr *self, const int delim, FILE *fp) { } STC_DEF cstr -cstr_replace_sv(csview in, csview search, csview repl, unsigned count) { +cstr_replace_sv(csview in, csview search, csview repl, int32_t count) { cstr out = cstr_NULL; - size_t from = 0; char* res; - if (!count) count = ~0U; + 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 size_t pos = (size_t)(res - in.str); + const intptr_t pos = (res - in.str); cstr_append_n(&out, in.str + from, pos - from); cstr_append_n(&out, repl.str, repl.size); from = pos + search.size; @@ -586,17 +586,17 @@ cstr_replace_sv(csview in, csview search, csview repl, unsigned count) { return out; } -STC_DEF void cstr_erase(cstr* self, const size_t pos, size_t len) { +STC_DEF void cstr_erase(cstr* self, const intptr_t pos, intptr_t len) { cstr_buf r = cstr_buffer(self); if (len > r.size - pos) len = r.size - pos; - memmove(&r.data[pos], &r.data[pos + len], r.size - (pos + len)); + c_memmove(&r.data[pos], &r.data[pos + len], r.size - (pos + len)); _cstr_set_size(self, r.size - len); } -STC_DEF void cstr_u8_erase(cstr* self, const size_t bytepos, const size_t u8len) { +STC_DEF void cstr_u8_erase(cstr* self, const intptr_t bytepos, const intptr_t u8len) { cstr_buf r = cstr_buffer(self); - size_t len = utf8_pos(r.data + bytepos, u8len); - memmove(&r.data[bytepos], &r.data[bytepos + len], r.size - (bytepos + len)); + intptr_t len = utf8_pos(r.data + bytepos, u8len); + c_memmove(&r.data[bytepos], &r.data[bytepos + len], r.size - (bytepos + len)); _cstr_set_size(self, r.size - len); } @@ -608,10 +608,10 @@ STC_DEF void cstr_u8_erase(cstr* self, const size_t bytepos, const size_t u8len) # pragma warning(disable: 4996) #endif -STC_DEF size_t cstr_vfmt(cstr* self, size_t start, const char* fmt, va_list args) { +STC_DEF intptr_t cstr_vfmt(cstr* self, intptr_t start, const char* fmt, va_list args) { va_list args2; va_copy(args2, args); - const size_t n = (size_t)vsnprintf(NULL, (size_t)0, fmt, args); + const int n = vsnprintf(NULL, 0ULL, fmt, args); vsprintf(cstr_reserve(self, start + n) + start, fmt, args2); va_end(args2); _cstr_set_size(self, start + n); @@ -632,19 +632,19 @@ STC_DEF cstr cstr_from_fmt(const char* fmt, ...) { return s; } -STC_DEF size_t cstr_append_fmt(cstr* self, const char* fmt, ...) { +STC_DEF intptr_t cstr_append_fmt(cstr* self, const char* fmt, ...) { va_list args; va_start(args, fmt); - const size_t n = cstr_vfmt(self, cstr_size(self), fmt, args); + const intptr_t n = cstr_vfmt(self, cstr_size(self), fmt, args); va_end(args); return n; } /* NB! self-data in args is UB */ -STC_DEF size_t cstr_printf(cstr* self, const char* fmt, ...) { +STC_DEF intptr_t cstr_printf(cstr* self, const char* fmt, ...) { va_list args; va_start(args, fmt); - const size_t n = cstr_vfmt(self, 0, fmt, args); + const intptr_t n = cstr_vfmt(self, 0, fmt, args); va_end(args); return n; } |
