diff options
| author | Tyge Løvset <[email protected]> | 2020-11-16 12:07:42 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-11-16 12:07:42 +0100 |
| commit | 231f2f6a034d5e2568c234479d39738947d6f514 (patch) | |
| tree | d389b6e045c039b8f20d0dc10d77343ec4ff9d45 | |
| parent | 56e3c5c17c55aab4f83e7f2d9f74288d5043bf6f (diff) | |
| download | STC-modified-231f2f6a034d5e2568c234479d39738947d6f514.tar.gz STC-modified-231f2f6a034d5e2568c234479d39738947d6f514.zip | |
Small update of the new cstr methods.
| -rw-r--r-- | stc/cstr.h | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -194,15 +194,18 @@ cstr_find(cstr_t s, const char* needle) { }
STC_INLINE bool
-cstr_contains(const cstr_t s, const char* needle) {
+cstr_contains(cstr_t s, const char* needle) {
return strstr(s.str, needle) != NULL;
}
STC_INLINE bool
-cstr_begins_with(const cstr_t s, const char* needle) {
- return strncmp(s.str, needle, strlen(needle)) == 0;
+cstr_begins_with(cstr_t s, const char* needle) {
+ for (;;) {
+ if (!(*needle && *s.str)) return *needle == 0;
+ if (*needle++ != *s.str++) return false;
+ }
}
STC_INLINE bool
-cstr_ends_with(const cstr_t s, const char* needle) {
+cstr_ends_with(cstr_t s, const char* needle) {
size_t n = strlen(needle), sz = cstr_size(s);
return n <= sz ? strcmp(s.str + sz - n, needle) == 0 : false;
}
|
