File tree Expand file tree Collapse file tree 1 file changed +10
-20
lines changed
Expand file tree Collapse file tree 1 file changed +10
-20
lines changed Original file line number Diff line number Diff line change 2121#include <stddef.h>
2222
2323#ifdef _WIN32
24- char * strcasestr (const char * haystack , const char * needle ) {
25- if (!haystack || !needle ) {
26- return NULL ;
27- }
28-
29- if (* needle == '\0' ) {
30- return (char * )haystack ;
31- }
32-
33- size_t needle_len = strlen (needle );
34- size_t haystack_len = strlen (haystack );
35-
36- if (needle_len > haystack_len ) {
37- return NULL ;
38- }
39-
40- for (size_t i = 0 ; i <= haystack_len - needle_len ; i ++ ) {
41- if (strnicmp (haystack + i , needle , needle_len ) == 0 ) {
42- return (char * )(haystack + i );
24+ char * strcasestr (const char * haystack , const char * needle ) {
25+ if (!haystack || !needle ) return NULL ;
26+ if (!* needle ) return (char * )haystack ;
27+ for (; * haystack ; ++ haystack ) {
28+ const char * h = haystack ;
29+ const char * n = needle ;
30+ while (* h && * n && tolower ((unsigned char )* h ) == tolower ((unsigned char )* n )) {
31+ ++ h ;
32+ ++ n ;
4333 }
34+ if (!* n ) return (char * )haystack ;
4435 }
45-
4636 return NULL ;
4737}
4838#endif
You can’t perform that action at this time.
0 commit comments