util: change return value of startswith() to non-const
This way we can use it on non-const strings, and don't end up with a const'ified result. This is similar to libc's strstr() which also takes a const string but returns a non-const one.
This commit is contained in:
parent
3fdbc82058
commit
11adc1aef7
|
@ -158,15 +158,23 @@ static inline bool isempty(const char *p) {
|
|||
return !p || !p[0];
|
||||
}
|
||||
|
||||
static inline const char *startswith(const char *s, const char *prefix) {
|
||||
if (strncmp(s, prefix, strlen(prefix)) == 0)
|
||||
return s + strlen(prefix);
|
||||
static inline char *startswith(const char *s, const char *prefix) {
|
||||
size_t l;
|
||||
|
||||
l = strlen(prefix);
|
||||
if (strncmp(s, prefix, l) == 0)
|
||||
return (char*) s + l;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline const char *startswith_no_case(const char *s, const char *prefix) {
|
||||
if (strncasecmp(s, prefix, strlen(prefix)) == 0)
|
||||
return s + strlen(prefix);
|
||||
static inline char *startswith_no_case(const char *s, const char *prefix) {
|
||||
size_t l;
|
||||
|
||||
l = strlen(prefix);
|
||||
if (strncasecmp(s, prefix, l) == 0)
|
||||
return (char*) s + l;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue