string-util-fundamental: postfix -> suffix, use streq

This commit is contained in:
Mike Yuan 2024-01-04 16:30:10 +08:00
parent 2a02a8db91
commit 3c1e6909d5
No known key found for this signature in database
GPG key ID: 417471C0A40F58B3
2 changed files with 10 additions and 10 deletions

View file

@ -33,14 +33,14 @@ sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) {
return (sd_char*) s + l;
}
sd_char* endswith(const sd_char *s, const sd_char *postfix) {
sd_char* endswith(const sd_char *s, const sd_char *suffix) {
size_t sl, pl;
assert(s);
assert(postfix);
assert(suffix);
sl = strlen(s);
pl = strlen(postfix);
pl = strlen(suffix);
if (pl == 0)
return (sd_char*) s + sl;
@ -48,20 +48,20 @@ sd_char* endswith(const sd_char *s, const sd_char *postfix) {
if (sl < pl)
return NULL;
if (strcmp(s + sl - pl, postfix) != 0)
if (!streq(s + sl - pl, suffix))
return NULL;
return (sd_char*) s + sl - pl;
}
sd_char* endswith_no_case(const sd_char *s, const sd_char *postfix) {
sd_char* endswith_no_case(const sd_char *s, const sd_char *suffix) {
size_t sl, pl;
assert(s);
assert(postfix);
assert(suffix);
sl = strlen(s);
pl = strlen(postfix);
pl = strlen(suffix);
if (pl == 0)
return (sd_char*) s + sl;
@ -69,7 +69,7 @@ sd_char* endswith_no_case(const sd_char *s, const sd_char *postfix) {
if (sl < pl)
return NULL;
if (strcasecmp(s + sl - pl, postfix) != 0)
if (!strcaseeq(s + sl - pl, suffix))
return NULL;
return (sd_char*) s + sl - pl;

View file

@ -59,8 +59,8 @@ static inline size_t strlen_ptr(const sd_char *s) {
sd_char *startswith(const sd_char *s, const sd_char *prefix) _pure_;
sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) _pure_;
sd_char *endswith(const sd_char *s, const sd_char *postfix) _pure_;
sd_char *endswith_no_case(const sd_char *s, const sd_char *postfix) _pure_;
sd_char *endswith(const sd_char *s, const sd_char *suffix) _pure_;
sd_char *endswith_no_case(const sd_char *s, const sd_char *suffix) _pure_;
static inline bool isempty(const sd_char *a) {
return !a || a[0] == '\0';