mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-04 15:09:40 +00:00
LibC: Add strcasestr()
strcasestr() behaves exactly like strstr(), except it ignores case for both inputs. This function is a nonstandard extension.
This commit is contained in:
parent
25c9dfbf90
commit
463ab21305
|
@ -359,6 +359,25 @@ char* strstr(char const* haystack, char const* needle)
|
|||
return const_cast<char*>(haystack);
|
||||
}
|
||||
|
||||
// https://linux.die.net/man/3/strcasestr
|
||||
char* strcasestr(char const* haystack, char const* needle)
|
||||
{
|
||||
char nch;
|
||||
char hch;
|
||||
|
||||
if ((nch = *needle++) != 0) {
|
||||
size_t len = strlen(needle);
|
||||
do {
|
||||
do {
|
||||
if ((hch = *haystack++) == 0)
|
||||
return nullptr;
|
||||
} while (toupper(hch) != toupper(nch));
|
||||
} while (strncasecmp(haystack, needle, len) != 0);
|
||||
--haystack;
|
||||
}
|
||||
return const_cast<char*>(haystack);
|
||||
}
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/strpbrk.html
|
||||
char* strpbrk(char const* s, char const* accept)
|
||||
{
|
||||
|
|
|
@ -43,6 +43,7 @@ __attribute__((warn_unused_result)) size_t strlcpy(char* dest, char const* src,
|
|||
char* strchr(char const*, int c);
|
||||
char* strchrnul(char const*, int c);
|
||||
char* strstr(char const* haystack, char const* needle);
|
||||
char* strcasestr(char const* haystack, char const* needle);
|
||||
char* strrchr(char const*, int c);
|
||||
|
||||
char* index(char const* str, int ch);
|
||||
|
|
Loading…
Reference in a new issue