Implement strcasestr
This commit is contained in:
36
libsrc/common/strcasestr.c
Normal file
36
libsrc/common/strcasestr.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
** strcasestr.c
|
||||
**
|
||||
** Colin Leroy-Mira, 2024
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
char* __fastcall__ strcasestr(const char *str, const char *substr) {
|
||||
size_t len_a = strlen(str);
|
||||
size_t len_b = strlen(substr);
|
||||
const char *end_str;
|
||||
|
||||
if (len_a < len_b)
|
||||
return NULL;
|
||||
|
||||
len_a -= len_b;
|
||||
|
||||
for (end_str = str + len_a + 1; str < end_str; str++) {
|
||||
if (!strncasecmp(str, substr, len_b))
|
||||
return (char *)str;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user