diff options
| author | Tyge Lovset <[email protected]> | 2023-02-01 08:38:45 +0100 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2023-02-01 08:38:45 +0100 |
| commit | 6ce6ef3307e52db5813d3c8d6a2cba52df06daf8 (patch) | |
| tree | 25af4be9fcd5e72778715b83ff312e157ca63b59 /docs/cstr_api.md | |
| parent | b677a0c3950b8294ba6458e682a885351273ac08 (diff) | |
| download | STC-modified-6ce6ef3307e52db5813d3c8d6a2cba52df06daf8.tar.gz STC-modified-6ce6ef3307e52db5813d3c8d6a2cba52df06daf8.zip | |
Massive update from unsigned sizes and indices to signed.
Diffstat (limited to 'docs/cstr_api.md')
| -rw-r--r-- | docs/cstr_api.md | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/docs/cstr_api.md b/docs/cstr_api.md index 48999654..6bf5c723 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -21,10 +21,10 @@ All cstr definitions and prototypes are available by including a single header f cstr cstr_init(void); // constructor; same as cstr_NULL. cstr cstr_lit(const char literal_only[]); // cstr from literal; no strlen() call. cstr cstr_from(const char* str); // constructor using strlen() -cstr cstr_from_n(const char* str, size_t n); // constructor with n first bytes of str +cstr cstr_from_n(const char* str, intptr_t n); // constructor with n first bytes of str cstr cstr_from_sv(csview sv); // construct cstr from csview -cstr cstr_with_capacity(size_t cap); -cstr cstr_with_size(size_t len, char fill); // repeat fill len times +cstr cstr_with_capacity(intptr_t cap); +cstr cstr_with_size(intptr_t len, char fill); // repeat fill len times cstr cstr_from_fmt(const char* fmt, ...); // printf() formatting cstr cstr_clone(cstr s); @@ -37,49 +37,49 @@ char* cstr_data(cstr* self); // cast to csview cstr_sv(const cstr* self); // cast to string view cstr_buf cstr_buffer(cstr* self); // cast to mutable buffer (with capacity) -size_t cstr_size(const cstr* self); -size_t cstr_capacity(const cstr* self); +intptr_t cstr_size(const cstr* self); +intptr_t cstr_capacity(const cstr* self); bool cstr_empty(const cstr* self); -char* cstr_reserve(cstr* self, size_t capacity); // return pointer to buffer -void cstr_resize(cstr* self, size_t len, char fill); +char* cstr_reserve(cstr* self, intptr_t capacity); // return pointer to buffer +void cstr_resize(cstr* self, intptr_t len, char fill); void cstr_shrink_to_fit(cstr* self); void cstr_clear(cstr* self); char* cstr_assign(cstr* self, const char* str); -char* cstr_assign_n(cstr* self, const char* str, size_t n); // assign n first bytes of str +char* cstr_assign_n(cstr* self, const char* str, intptr_t n); // assign n first bytes of str char* cstr_assign_sv(cstr* self, csview sv); char* cstr_copy(cstr* self, cstr s); // copy-assign a cstr int cstr_printf(cstr* self, const char* fmt, ...); // source and target must not overlap. char* cstr_append(cstr* self, const char* str); -char* cstr_append_n(cstr* self, const char* str, size_t n); // append n first bytes of str +char* cstr_append_n(cstr* self, const char* str, intptr_t n); // append n first bytes of str char* cstr_append_sv(cstr* self, csview str); char* cstr_append_s(cstr* self, cstr str); int cstr_append_fmt(cstr* self, const char* fmt, ...); // printf() formatting -char* cstr_append_uninit(cstr* self, size_t len); // return ptr to start of uninited data +char* cstr_append_uninit(cstr* self, intptr_t len); // return ptr to start of uninited data void cstr_push(cstr* self, const char* chr); // append one utf8 char void cstr_pop(cstr* self); // pop one utf8 char -void cstr_insert(cstr* self, size_t pos, const char* ins); -void cstr_insert_sv(cstr* self, size_t pos, csview ins); -void cstr_insert_s(cstr* self, size_t pos, cstr ins); +void cstr_insert(cstr* self, intptr_t pos, const char* ins); +void cstr_insert_sv(cstr* self, intptr_t pos, csview ins); +void cstr_insert_s(cstr* self, intptr_t pos, cstr ins); -void cstr_erase(cstr* self, size_t pos, size_t len); // erase len bytes from pos +void cstr_erase(cstr* self, intptr_t pos, intptr_t len); // erase len bytes from pos void cstr_replace(cstr* self, const char* search, const char* repl, unsigned count = MAX_INT); cstr cstr_replace_sv(csview in, csview search, csview repl, unsigned count); -void cstr_replace_at(cstr* self, size_t pos, size_t len, const char* repl); // replace at a position -void cstr_replace_at_sv(cstr* self, size_t pos, size_t len, const csview repl); -void cstr_replace_at_s(cstr* self, size_t pos, size_t len, cstr repl); +void cstr_replace_at(cstr* self, intptr_t pos, intptr_t len, const char* repl); // replace at a position +void cstr_replace_at_sv(cstr* self, intptr_t pos, intptr_t len, const csview repl); +void cstr_replace_at_s(cstr* self, intptr_t pos, intptr_t len, cstr repl); bool cstr_equals(const cstr* self, const char* str); bool cstr_equals_sv(const cstr* self, csview sv); bool cstr_equals_s(const cstr* self, cstr s); -size_t cstr_find(const cstr* self, const char* search); -size_t cstr_find_at(const cstr* self, size_t pos, const char* search); // search from pos +intptr_t cstr_find(const cstr* self, const char* search); +intptr_t cstr_find_at(const cstr* self, intptr_t pos, const char* search); // search from pos bool cstr_contains(const cstr* self, const char* search); bool cstr_starts_with(const cstr* self, const char* str); @@ -96,13 +96,13 @@ bool cstr_getdelim(cstr *self, int delim, FILE *stream); // does no #### UTF8 methods ```c -size_t cstr_u8_size(const cstr* self); // number of utf8 codepoints -size_t cstr_u8_size_n(const cstr self, size_t nbytes); // utf8 size within n bytes -size_t cstr_u8_to_pos(const cstr* self, size_t u8idx); // byte pos offset at utf8 codepoint index -const char* cstr_u8_at(const cstr* self, size_t u8idx); // char* position at utf8 codepoint index -csview cstr_u8_chr(const cstr* self, size_t u8idx); // get utf8 character as a csview -void cstr_u8_replace_at(cstr* self, size_t bytepos, size_t u8len, csview repl); // replace u8len utf8 chars -void cstr_u8_erase(cstr* self, size_t bytepos, size_t u8len); // erase u8len codepoints from pos +intptr_t cstr_u8_size(const cstr* self); // number of utf8 codepoints +intptr_t cstr_u8_size_n(const cstr self, intptr_t nbytes); // utf8 size within n bytes +intptr_t cstr_u8_to_pos(const cstr* self, intptr_t u8idx); // byte pos offset at utf8 codepoint index +const char* cstr_u8_at(const cstr* self, intptr_t u8idx); // char* position at utf8 codepoint index +csview cstr_u8_chr(const cstr* self, intptr_t u8idx); // get utf8 character as a csview +void cstr_u8_replace_at(cstr* self, intptr_t bytepos, intptr_t u8len, csview repl); // replace u8len utf8 chars +void cstr_u8_erase(cstr* self, intptr_t bytepos, intptr_t u8len); // erase u8len codepoints from pos // iterate utf8 codepoints cstr_iter cstr_begin(const cstr* self); @@ -128,7 +128,7 @@ bool cstr_istarts_with(const cstr* self, const char* str); bool cstr_iends_with(const cstr* self, const char* str); // " ``` -Note that all methods with arguments `(..., const char* str, size_t n)`, `n` must be within the range of `str` length. +Note that all methods with arguments `(..., const char* str, intptr_t n)`, `n` must be within the range of `str` length. #### Helper methods: ```c @@ -136,7 +136,7 @@ int cstr_cmp(const cstr* s1, const cstr* s2); bool cstr_eq(const cstr* s1, const cstr* s2); bool cstr_hash(const cstr* self); -char* cstrnstrn(const char* str, const char* search, size_t slen, size_t nlen); +char* cstrnstrn(const char* str, const char* search, intptr_t slen, intptr_t nlen); ``` ## Types @@ -145,8 +145,8 @@ char* cstrnstrn(const char* str, const char* search, size_t slen, size_t |:----------------|:-------------------------------------------|:---------------------| | `cstr` | `struct { ... }` | The string type | | `cstr_value` | `char` | String element type | -| `csview` | `struct { const char *str; size_t size; }` | String view type | -| `cstr_buf` | `struct { char *data; size_t size, cap; }` | String buffer type | +| `csview` | `struct { const char *str; intptr_t size; }` | String view type | +| `cstr_buf` | `struct { char *data; intptr_t size, cap; }` | String buffer type | ## Constants and macros @@ -162,7 +162,7 @@ char* cstrnstrn(const char* str, const char* search, size_t slen, size_t int main() { c_AUTO (cstr, s0, s1, full_path) { s0 = cstr_lit("Initialization without using strlen()."); - printf("%s\nLength: %" c_ZU "\n\n", cstr_str(&s0), cstr_size(&s0)); + printf("%s\nLength: %" c_ZI "\n\n", cstr_str(&s0), cstr_size(&s0)); s1 = cstr_lit("one-nine-three-seven-five."); printf("%s\n", cstr_str(&s1)); |
