summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-12-01 13:38:43 +0100
committerTyge Løvset <[email protected]>2020-12-01 13:38:43 +0100
commit722b3c9140025a6f159fd2410d1eed5b49651f42 (patch)
treed5000916538d0d3f7bbe9b5118cd36bab6df2f41
parent86815cbca6fe8a0771b4eb33ee93921b27a999bf (diff)
downloadSTC-modified-722b3c9140025a6f159fd2410d1eed5b49651f42.tar.gz
STC-modified-722b3c9140025a6f159fd2410d1eed5b49651f42.zip
Added numbers before functions in cstr docs.
-rw-r--r--docs/cstr_api.md114
-rw-r--r--stc/cstr.h6
2 files changed, 60 insertions, 60 deletions
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index d1941dd1..823f13ee 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -30,128 +30,128 @@ All cstr definitions and prototypes may be included in your C source file by inc
The interface for cstr_t:
```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)
+(1) cstr_t cstr_init(void);
+(2) cstr_t cstr_with_capacity(size_t cap);
+(3) cstr_t cstr_with_size(size_t len, char fill);
+(4) cstr_t cstr_from(const char* str);
+(5) cstr_t cstr_from_n(const char* str, size_t len);
+(6) cstr_t cstr_from_fmt(const char* fmt, ...);
+(7) cstr_t cstr_clone(cstr_t s);
```
(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);
+(1) 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);
+(1) size_t cstr_size(cstr_t s);
+(2) size_t cstr_length(cstr_t s);
+(3) size_t cstr_capacity(cstr_t s);
+(4) 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);
+(1) char* cstr_front(cstr_t* self);
+(2) 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);
+(1) size_t cstr_reserve(cstr_t* self, size_t cap);
+(2) void cstr_resize(cstr_t* self, size_t len, char fill);
+(3) 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)
+(1) cstr_t* cstr_assign(cstr_t* self, const char* str);
+(2) cstr_t* cstr_assign_n(cstr_t* self, const char* str, size_t len);
+(3) cstr_t* cstr_take(cstr_t* self, cstr_t s);
+(4) cstr_t cstr_move(cstr_t* self);
```
(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 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)
-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) cstr_t* cstr_append(cstr_t* self, const char* str);
+(2) cstr_t* cstr_append_n(cstr_t* self, const char* str, size_t len);
+(3) cstr_t* cstr_push_back(cstr_t* self, char ch);
+(4) void cstr_insert(cstr_t* self, size_t pos, const char* str);
+(5) void cstr_insert_n(cstr_t* self, size_t pos, const char* str, size_t n);
```
(1) Append `str` to `*self`. (2) Append substring `str` limited by `len`. (3), Append character `ch`.
(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);
+(1) void cstr_erase(cstr_t* self, size_t pos, size_t n);
+(2) 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);
+(1) void cstr_replace(cstr_t* self, size_t pos, size_t len, const char* str);
+(2) void cstr_replace_n(cstr_t* self, size_t pos, size_t len, const char* str, size_t n);
```
### 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);
-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);
+(1) size_t cstr_find(cstr_t s, const char* substr);
+(2) size_t cstr_find_n(cstr_t s, const char* substr, size_t pos, size_t nlen);
+(3) bool cstr_contains(cstr_t s, const char* substr);
+(4) bool cstr_begins_with(cstr_t s, const char* substr);
+(5) 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);
+(5) size_t cstr_ifind_n(cstr_t s, const char* substr, size_t pos, size_t nlen);
+(6) bool cstr_icontains(cstr_t s, const char* substr);
+(7) bool cstr_ibegins_with(cstr_t s, const char* substr);
+(8) bool cstr_iends_with(cstr_t s, const char* substr);
```
### Comparisons and equality
```c
-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);
+(1) bool cstr_equals(cstr_t s, const char* str);
+(2) bool cstr_equals_s(cstr_t s, cstr_t s2);
+(3) int cstr_compare(const cstr_t *s1, const cstr_t *s2);
-bool cstr_iequals(cstr_t s, const char* str);
+(4) 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)
+(1) cstr_iter_t cstr_begin(cstr_t* self);
+(2) cstr_iter_t cstr_end(cstr_t* self);
+(3) void cstr_next(cstr_iter_t* it);
+(4) char* cstr_itval(cstr_iter_t it);
```
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);
+(1) bool cstr_getline(cstr_t *self, FILE *stream);
+(2) 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* 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);
+(1) int c_strncasecmp(const char* s1, const char* s2, size_t n);
+(2) char* c_strnfind(const char* str, const char* needle, size_t nmax);
+(3) char* c_istrnfind(const char* str, const char* needle, size_t nmax);
+(4) 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);
+(1) const char* cstr_to_raw(const cstr_t* x);
+(2) int cstr_compare_raw(const char** x, const char** y);
+(3) bool cstr_equals_raw(const char** x, const char** y);
+(4) uint32_t cstr_hash_raw(const char* const* spp, size_t ignored);
```
Example:
diff --git a/stc/cstr.h b/stc/cstr.h
index 6adea9d3..28deb364 100644
--- a/stc/cstr.h
+++ b/stc/cstr.h
@@ -416,9 +416,9 @@ cstr_ifind_n(cstr_t s, const char* needle, size_t pos, size_t nlen) {
STC_DEF int
c_strncasecmp(const char* s1, const char* s2, size_t n) {
- while (n && *s1 && tolower(*s1) == tolower(*s2))
- ++s1, ++s2, --n;
- return n ? tolower(*s1) - tolower(*s2) : 0;
+ int ret = 0;
+ while (n-- && (ret = tolower(*s1++) - tolower(*s2)) == 0 && *s2++) ;
+ return ret;
}
STC_DEF char*