Introduce starts_with() and starts_with_ci()
Create user-defined functions to check whether a string contains a certain prefix instead of messing around with strncmp() and strncasecmp(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
12
src/utils.c
12
src/utils.c
@@ -1602,3 +1602,15 @@ asprintf(char **str, const char *format, ...)
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int starts_with(const char *s, const char *p)
|
||||
{
|
||||
for (; *p && *p == *s; s++, p++);
|
||||
return (*p == '\0');
|
||||
}
|
||||
|
||||
int starts_with_ci(const char *s, const char *p)
|
||||
{
|
||||
for (; *p && tolower(*p) == tolower(*s); s++, p++);
|
||||
return (*p == '\0');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user