diff --git a/common/str.cpp b/common/str.cpp index 2ae366bca8e..77a50bd768f 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -1323,3 +1323,22 @@ char *scumm_strdup(const char *in) { } return out; } + +// Portable implementation of strcasestr. +const char *scumm_strcasestr(const char *s, const char *find) { + char c, sc; + size_t len; + + if ((c = *find++) != 0) { + c = (char)tolower((unsigned char)c); + len = strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while ((char)tolower((unsigned char)sc) != c); + } while (scumm_strnicmp(s, find, len) != 0); + s--; + } + return s; +} diff --git a/common/str.h b/common/str.h index c19b2ef6999..bce55fd2103 100644 --- a/common/str.h +++ b/common/str.h @@ -568,4 +568,6 @@ extern char *scumm_strdup(const char *in); extern int scumm_compareDictionary(const char *s1, const char *s2); extern const char *scumm_skipArticle(const char *s1); +extern const char *scumm_strcasestr(const char *s, const char *find); + #endif