summaryrefslogtreecommitdiffhomepage
path: root/docs/cstr_api.md
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-11-30 16:05:04 +0100
committerTyge Løvset <[email protected]>2020-11-30 16:05:04 +0100
commit86e4768e3c46879421772147b377395fd232a7cd (patch)
tree4448f0911b24d2e86bf4d0c008e483348e0fe0a9 /docs/cstr_api.md
parent0f1b858bd3708a1cad10912696fe9443fda7ce2b (diff)
downloadSTC-modified-86e4768e3c46879421772147b377395fd232a7cd.tar.gz
STC-modified-86e4768e3c46879421772147b377395fd232a7cd.zip
Formatting in str docs.
Diffstat (limited to 'docs/cstr_api.md')
-rw-r--r--docs/cstr_api.md146
1 files changed, 72 insertions, 74 deletions
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index b6a516a6..47c4716c 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -4,17 +4,17 @@ This describes the API of string type **cstr_t**.
## Types
-| Type name | Type definition | Used to represent... |
-|:------------------|:---------------------------------------|:-------------------------------------|
-| `cstr_t` | `struct { const char *str; }` | The string type |
-| `cstr_value_t` | `char` | The string element type |
-| `cstr_iter_t` | `struct { cstr_value_t *val; }` | cstr_t iterator |
+| Type name | Type definition | Used to represent... |
+|:------------------|:---------------------------------|:---------------------------|
+| `cstr_t` | `struct { const char *str; }` | The string type |
+| `cstr_value_t` | `char` | The string element type |
+| `cstr_iter_t` | `struct { cstr_value_t *val; }` | cstr_t iterator |
## Constants and macros
-| Name | Value / Returns |
+| Name | Value |
|:---------------------------|:-----------------|
-| `cstr_npos` | `-1ULL` |
+| `cstr_npos` | `-1ull` |
| `cstr_size(str) | |
| `cstr_capacity(str) | |
| `cstr_empty(str) | |
@@ -32,128 +32,126 @@ All cstr definitions and prototypes may be included in your C source file by inc
The interfaces to create a cstr_t object:
```c
-cstr_t cstr_init( void ); (1)
-cstr_t cstr_with_capacity( size_t cap ); (2)
-cstr_t cstr_with_size( size_t len, char fill ); (3)
-cstr_t cstr_from( const char* str ); (4)
-cstr_t cstr_from_n( const char* str, size_t len ); (5)
-cstr_t cstr_from_fmt( const char* fmt, ... ); (6)
-cstr_t cstr_clone( cstr_t s ); (7)
+cstr_t cstr_init(void); (1)
+cstr_t cstr_with_capacity(size_t cap); (2)
+cstr_t cstr_with_size(size_t len, char fill); (3)
+cstr_t cstr_from(const char* str); (4)
+cstr_t cstr_from_n(const char* str, size_t len); (5)
+cstr_t cstr_from_fmt(const char* fmt, ...); (6)
+cstr_t cstr_clone(cstr_t s); (7)
```
(1) Create an empty cstr_t, (2) with capacity `cap`. (3) Create a cstr_t by repeating the `fill` character `len` times. (4) Construct a cstr_t from a const char* str, and (5) limit the length by `len` and `strlen(str)`. (6) Construct a string from a formatted const char* `fmt` and arguments, using `printf()` formatting. (7) Construct a new string by cloning another cstr_t `s`.
### Destruction
```c
-void cstr_del( cstr_t *self );
+void cstr_del(cstr_t *self);
```
Free the allocated memory used by string.
### Get string properties
```c
-size_t cstr_size( cstr_t s );
-size_t cstr_length( cstr_t s );
-size_t cstr_capacity( cstr_t s );
-bool cstr_empty( cstr_t s );
+size_t cstr_size(cstr_t s);
+size_t cstr_length(cstr_t s);
+size_t cstr_capacity(cstr_t s);
+bool cstr_empty(cstr_t s);
+```
+
+### Get references to front and back of a cstr_t
+```c
+char* cstr_front(cstr_t* self);
+char* cstr_back(cstr_t* self);
```
### Reserve capcacity, resize, and clear
```c
-size_t cstr_reserve( cstr_t* self, size_t cap );
-void cstr_resize( cstr_t* self, size_t len, char fill );
-void cstr_clear( cstr_t* self );
+size_t cstr_reserve(cstr_t* self, size_t cap);
+void cstr_resize(cstr_t* self, size_t len, char fill);
+void cstr_clear(cstr_t* self);
```
### Assignment and transfer of ownership
```c
-cstr_t* cstr_assign( cstr_t* self, const char* str ); (1)
-cstr_t* cstr_assign_n( cstr_t* self, const char* str, size_t len ); (2)
-cstr_t* cstr_take( cstr_t* self, cstr_t s ); (3)
-cstr_t cstr_move( cstr_t* self ); (4)
+cstr_t* cstr_assign(cstr_t* self, const char* str); (1)
+cstr_t* cstr_assign_n(cstr_t* self, const char* str, size_t len); (2)
+cstr_t* cstr_take(cstr_t* self, cstr_t s); (3)
+cstr_t cstr_move(cstr_t* self); (4)
```
(1) Assign `str` to `*self`, (2) assign substring `str` limited by `len` and `strlen(str)`. (3) Take the constructed or moved string `s`, i.e., no allocation takes place. (4) Explicitly move `*self` to the caller of the method; `*self` becomes an empty string after move.
-### Append characters
+### Append and insert characters
```c
-cstr_t* cstr_append( cstr_t* self, const char* str ); (1)
-cstr_t* cstr_append_n( cstr_t* self, const char* str, size_t len ); (2)
-cstr_t* cstr_push_back( cstr_t* self, char ch ); (3)
+cstr_t* cstr_append(cstr_t* self, const char* str); (1)
+cstr_t* cstr_append_n(cstr_t* self, const char* str, size_t len); (2)
+cstr_t* cstr_push_back(cstr_t* self, char ch); (3)
+void cstr_insert(cstr_t* self, size_t pos, const char* str); (4)
+void cstr_insert_n(cstr_t* self, size_t pos, const char* str, size_t n); (5)
```
(1) Append `str` to `*self`. (2) Append substring `str` limited by `len`. (3), Append character `ch`.
-
-### Insert characters
-```c
-void cstr_insert( cstr_t* self, size_t pos, const char* str ); (1)
-void cstr_insert_n( cstr_t* self, size_t pos, const char* str, size_t n ); (2)
-```
-Insert a string at the specified position (1), or insert string limited with n / strlen(str).
+(4) Insert a string at the specified position (5), or insert string limited with n / strlen(str).
### Erase characters
```c
-void cstr_erase( cstr_t* self, size_t pos, size_t n );
-void cstr_pop_back( cstr_t* self );
+void cstr_erase(cstr_t* self, size_t pos, size_t n);
+void cstr_pop_back(cstr_t* self);
```
### Replace substring
```c
-void cstr_replace( cstr_t* self, size_t pos, size_t len, const char* str );
-void cstr_replace_n( cstr_t* self, size_t pos, size_t len, const char* str, size_t n );
+void cstr_replace(cstr_t* self, size_t pos, size_t len, const char* str);
+void cstr_replace_n(cstr_t* self, size_t pos, size_t len, const char* str, size_t n);
```
-### Search for substring
+### Search for substring, case sensitive / insensitive
```c
-size_t cstr_find( cstr_t s, const char* substr );
-size_t cstr_find_n( cstr_t s, const char* substr, size_t pos, size_t nlen );
-size_t cstr_ifind_n( cstr_t s, const char* substr, size_t pos, size_t nlen );
-bool cstr_contains( cstr_t s, const char* substr );
-bool cstr_icontains( cstr_t s, const char* substr );
-bool cstr_begins_with( cstr_t s, const char* substr );
-bool cstr_ibegins_with( cstr_t s, const char* substr );
-bool cstr_ends_with( cstr_t s, const char* substr );
-bool cstr_iends_with( cstr_t s, const char* substr );
+size_t cstr_find(cstr_t s, const char* substr);
+size_t cstr_find_n(cstr_t s, const char* substr, size_t pos, size_t nlen);
+bool cstr_contains(cstr_t s, const char* substr);
+bool cstr_begins_with(cstr_t s, const char* substr);
+bool cstr_ends_with(cstr_t s, const char* substr);
+
+size_t cstr_ifind_n(cstr_t s, const char* substr, size_t pos, size_t nlen);
+bool cstr_icontains(cstr_t s, const char* substr);
+bool cstr_ibegins_with(cstr_t s, const char* substr);
+bool cstr_iends_with(cstr_t s, const char* substr);
```
### Comparisons and equality
```c
-bool cstr_equals( cstr_t s1, const char* str );
-bool cstr_iequals( cstr_t s1, const char* str );
-bool cstr_equals_s( cstr_t s1, cstr_t s2 );
-int cstr_compare( const cstr_t *s1, const cstr_t *s2 );
-```
+bool cstr_equals(cstr_t s, const char* str);
+bool cstr_equals_s(cstr_t s, cstr_t s2);
+int cstr_compare(const cstr_t *s1, const cstr_t *s2);
-### Get references to front and back of a cstr_t
-```c
-char* cstr_front( cstr_t* self );
-char* cstr_back( cstr_t* self );
+bool cstr_iequals(cstr_t s, const char* str);
```
### Iterator methods
```c
-cstr_iter_t cstr_begin( cstr_t* self ); (1)
-cstr_iter_t cstr_end( cstr_t* self ); (2)
-void cstr_next( cstr_iter_t* it ); (3)
-char* cstr_itval( cstr_iter_t it ); (4)
+cstr_iter_t cstr_begin(cstr_t* self); (1)
+cstr_iter_t cstr_end(cstr_t* self); (2)
+void cstr_next(cstr_iter_t* it); (3)
+char* cstr_itval(cstr_iter_t it); (4)
```
To iterate though a string, one can use the generic `c_foreach` macro. E.g. `c_foreach (i, cstr, mystr) printf("%c", *i.val);`. This is equivalent to `for (size_t i=0; i<cstr_size(mystr); ++i) printf("%c", mystr.str[i])`.
```c
-bool cstr_getline( cstr_t *self, FILE *stream );
-bool cstr_getdelim( cstr_t *self, int delim, FILE *stream );
+bool cstr_getline(cstr_t *self, FILE *stream);
+bool cstr_getdelim(cstr_t *self, int delim, FILE *stream);
```
## Other string methods
### Non-members
```c
-int c_strncasecmp( const char* s1, const char* s2, size_t n );
-char* c_strnfind( const char* s, const char* needle, size_t nmax );
-char* c_istrnfind( const char* s, const char* needle, size_t nmax );
-uint32_t c_string_hash( const char* str );
+int c_strncasecmp(const char* s1, const char* s2, size_t n);
+char* c_strnfind(const char* str, const char* needle, size_t nmax);
+char* c_istrnfind(const char* str, const char* needle, size_t nmax);
+uint32_t c_string_hash(const char* str);
```
### Helper methods
```c
-const char* cstr_to_raw( const cstr_t* x );
-int cstr_compare_raw( const char** x, const char** y );
-bool cstr_equals_raw( const char** x, const char** y );
-uint32_t cstr_hash_raw( const char* const* spp, size_t ignored );
+const char* cstr_to_raw(const cstr_t* x);
+int cstr_compare_raw(const char** x, const char** y);
+bool cstr_equals_raw(const char** x, const char** y);
+uint32_t cstr_hash_raw(const char* const* spp, size_t ignored);
```