From c94e29ed02be8c3df19c0db41f45959398582d12 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 26 May 2015 02:31:29 +0200 Subject: [PATCH] Create rarch_strcasestr --- libretro-common/compat/compat.c | 24 ++++++++++++++++++++++++ libretro-common/include/compat/strl.h | 2 ++ tasks/task_database.c | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/libretro-common/compat/compat.c b/libretro-common/compat/compat.c index 454f2f2dfc..1a1df67ee1 100644 --- a/libretro-common/compat/compat.c +++ b/libretro-common/compat/compat.c @@ -364,3 +364,27 @@ char *rarch_strtok_r__(char *str, const char *delim, char **saveptr) #endif +/* + * Find the first occurrence of find in s, ignore case. + */ +char *rarch_strcasestr(const char *s, const char *find) +{ + char c, sc; + size_t len; + + if ((c = *find++) != 0) + { + c = tolower((unsigned char)c); + len = strlen(find); + do + { + do + { + if ((sc = *s++) == 0) + return (NULL); + }while ((char)tolower((unsigned char)sc) != c); + }while (strncasecmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} diff --git a/libretro-common/include/compat/strl.h b/libretro-common/include/compat/strl.h index 8f92e032d8..896dd2e7ac 100644 --- a/libretro-common/include/compat/strl.h +++ b/libretro-common/include/compat/strl.h @@ -44,6 +44,8 @@ extern "C" { size_t strlcpy(char *dest, const char *source, size_t size); size_t strlcat(char *dest, const char *source, size_t size); +char *rarch_strcasestr(const char *s, const char *find); + #ifdef __cplusplus } #endif diff --git a/tasks/task_database.c b/tasks/task_database.c index abc014b93c..ca61204068 100644 --- a/tasks/task_database.c +++ b/tasks/task_database.c @@ -210,7 +210,7 @@ static int database_info_iterate_crc_lookup( entry_state_crc, db_info_entry->crc32, db_info_entry->name); #endif - if (strcasestr(entry_state_crc, db_info_entry->crc32)) + if (rarch_strcasestr(entry_state_crc, db_info_entry->crc32)) return database_info_list_iterate_found_match(db_state, db); } }