From b36751b7970a699f453da471261d258868741281 Mon Sep 17 00:00:00 2001 From: skotlex Date: Fri, 28 Apr 2006 14:36:55 +0000 Subject: - Added function stristr to strlib.c, used by mob.c and item_db.c for case-insensitive seeks. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@6345 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/strlib.c | 35 +++++++++++++++++++++++++++++++++++ src/common/strlib.h | 1 + 2 files changed, 36 insertions(+) (limited to 'src/common') diff --git a/src/common/strlib.c b/src/common/strlib.c index 94f815839..d62bf4f46 100644 --- a/src/common/strlib.c +++ b/src/common/strlib.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "strlib.h" #include "utils.h" @@ -137,6 +138,40 @@ char *trim(char *str, const char *delim) return str; } + +//stristr: Case insensitive version of strstr, code taken from +//http://www.daniweb.com/code/snippet313.html, Dave Sinkula +// +const char *stristr(const char *haystack, const char *needle) +{ + if ( !*needle ) + { + return haystack; + } + for ( ; *haystack; ++haystack ) + { + if ( toupper(*haystack) == toupper(*needle) ) + { + /* + * Matched starting char -- loop through remaining chars. + */ + const char *h, *n; + for ( h = haystack, n = needle; *h && *n; ++h, ++n ) + { + if ( toupper(*h) != toupper(*n) ) + { + break; + } + } + if ( !*n ) /* matched all of 'needle' to null termination */ + { + return haystack; /* return the start of the match */ + } + } + } + return 0; +} + #ifdef __WIN32 char *_strtok_r(char *s1, const char *s2, char **lasts) { diff --git a/src/common/strlib.h b/src/common/strlib.h index 51d865149..225228c74 100644 --- a/src/common/strlib.h +++ b/src/common/strlib.h @@ -20,4 +20,5 @@ char *_strtok_r(char *s1, const char *s2, char **lasts); // custom functions int remove_control_chars(unsigned char *); char *trim(char *str, const char *delim); +const char *stristr(const char *haystack, const char *needle); #endif -- cgit v1.2.3-70-g09d2