diff options
| -rw-r--r-- | docs/cstr_api.md | 15 | ||||
| -rw-r--r-- | stc/cstr.h | 17 |
2 files changed, 15 insertions, 17 deletions
diff --git a/docs/cstr_api.md b/docs/cstr_api.md index 11cd1214..b3e138a6 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -19,7 +19,7 @@ cstr cstr_init(void); // constru cstr cstr_with_capacity(size_t cap); cstr cstr_with_size(size_t len, char fill); // repeat fill len times cstr cstr_from(const char* str); -cstr cstr_from_n(const char* str, size_t len); +cstr cstr_from_n(const char* str, size_t n); cstr cstr_from_fmt(const char* fmt, ...); // printf() formatting cstr cstr_clone(cstr s); @@ -34,12 +34,12 @@ size_t cstr_reserve(cstr* self, size_t capacity); void cstr_resize(cstr* self, size_t len, char fill); void cstr_clear(cstr* self); cstr* cstr_assign(cstr* self, const char* str); -cstr* cstr_assign_n(cstr* self, const char* str, size_t len); +cstr* cstr_assign_n(cstr* self, const char* str, size_t n); cstr* cstr_take(cstr* self, cstr s); // take the constructed or moved string cstr cstr_move(cstr* self); // move string to caller, leave empty string cstr* cstr_append(cstr* self, const char* str); -cstr* cstr_append_n(cstr* self, const char* str, size_t len); // appends max len characters +cstr* cstr_append_n(cstr* self, const char* str, size_t n); // appends len characters void cstr_push_back(cstr* self, char ch); void cstr_pop_back(cstr* self); void cstr_insert(cstr* self, size_t pos, const char* str); @@ -54,8 +54,8 @@ bool cstr_equals(cstr s, const char* str); bool cstr_equals_s(cstr s, cstr s2); bool cstr_iequals(cstr s, const char* str); // prefix i = case-insensitive size_t cstr_find(cstr s, const char* substr); -size_t cstr_find_n(cstr s, const char* substr, size_t pos, size_t nlen); -size_t cstr_ifind_n(cstr s, const char* substr, size_t pos, size_t nlen); +size_t cstr_find_n(cstr s, const char* substr, size_t pos, size_t n); +size_t cstr_ifind_n(cstr s, const char* substr, size_t pos, size_t n); bool cstr_contains(cstr s, const char* substr); bool cstr_icontains(cstr s, const char* substr); bool cstr_begins_with(cstr s, const char* substr); @@ -79,10 +79,9 @@ const char* cstr_c_str(const cstr* 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* x, size_t ignored); -char* c_strcopy(const char* src, char* dst, const char* dst_end, int termin); 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); +char* c_strnfind(const char* str, const char* needle, size_t n); +char* c_istrnfind(const char* str, const char* needle, size_t n); uint32_t c_strhash(const char* str); ``` Helper methods, used by other container types. @@ -50,8 +50,8 @@ STC_API size_t cstr_find_n(cstr_t s, const char* needle, size_t pos, size_t nle STC_API size_t cstr_ifind_n(cstr_t s, const char* needle, size_t pos, size_t nlen);
STC_API int c_strncasecmp(const char* s1, const char* s2, size_t n);
-STC_API char* c_strnfind(const char* s, const char* needle, size_t nmax);
-STC_API char* c_istrnfind(const char* s, const char* needle, size_t nmax);
+STC_API char* c_strnstr(const char* s, const char* needle, size_t nmax);
+STC_API char* c_strncasestr(const char* s, const char* needle, size_t nmax);
struct cstr_rep { size_t size, cap; char str[sizeof(size_t)]; };
#define cstr_rep_(self) c_container_of((self)->str, struct cstr_rep, str)
@@ -194,7 +194,7 @@ cstr_contains(cstr_t s, const char* needle) { }
STC_INLINE bool
cstr_icontains(cstr_t s, const char* needle) {
- return c_istrnfind(s.str, needle, cstr_npos) != NULL;
+ return c_strncasestr(s.str, needle, cstr_npos) != NULL;
}
STC_INLINE bool
@@ -385,17 +385,16 @@ cstr_find(cstr_t s, const char* needle) { STC_DEF size_t
cstr_find_n(cstr_t s, const char* needle, size_t pos, size_t nlen) {
if (pos > cstr_rep_(&s)->size) return cstr_npos;
- char* res = c_strnfind(s.str + pos, needle, nlen);
+ char* res = c_strnstr(s.str + pos, needle, nlen);
return res ? res - s.str : cstr_npos;
}
STC_DEF size_t
cstr_ifind_n(cstr_t s, const char* needle, size_t pos, size_t nlen) {
if (pos > cstr_rep_(&s)->size) return cstr_npos;
- char* res = c_istrnfind(s.str + pos, needle, nlen);
+ char* res = c_strncasestr(s.str + pos, needle, nlen);
return res ? res - s.str : cstr_npos;
}
-/* http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord */
STC_DEF int
c_strncasecmp(const char* s1, const char* s2, size_t n) {
@@ -405,7 +404,7 @@ c_strncasecmp(const char* s1, const char* s2, size_t n) { }
STC_DEF char*
-c_strnfind(const char* s, const char* needle, size_t nmax) {
+c_strnstr(const char* s, const char* needle, size_t nmax) {
ptrdiff_t sum = 0;
const char *t = s, *p = needle;
while (*p && nmax--) {
@@ -422,7 +421,7 @@ c_strnfind(const char* s, const char* needle, size_t nmax) { }
STC_DEF char*
-c_istrnfind(const char* s, const char* needle, size_t nmax) {
+c_strncasestr(const char* s, const char* needle, size_t nmax) {
ptrdiff_t sum = 0;
const char *t = s, *p = needle;
while (*p && nmax--) {
@@ -438,6 +437,6 @@ c_istrnfind(const char* s, const char* needle, size_t nmax) { }
}
+/* http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord */
#endif
-
#endif
\ No newline at end of file |
