diff --git a/NEWS b/NEWS index 4857d2cda..ae617cdce 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ ver 0.20.11 (not yet released) - curl: support Content-Type application/xml * decoder - ffmpeg: more reliable song duration +* fix case insensitive search without libicu ver 0.20.10 (2017/08/24) * decoder diff --git a/configure.ac b/configure.ac index 11d869e2b..ad8b6462a 100644 --- a/configure.ac +++ b/configure.ac @@ -241,6 +241,7 @@ AC_CHECK_FUNCS(getpwnam_r getpwuid_r) AC_CHECK_FUNCS(initgroups) AC_CHECK_FUNCS(fnmatch) AC_CHECK_FUNCS(strndup) +AC_CHECK_FUNCS(strcasestr) if test x$host_is_linux = xyes; then MPD_OPTIONAL_FUNC(eventfd, eventfd, USE_EVENTFD) diff --git a/src/lib/icu/CaseFold.hxx b/src/lib/icu/CaseFold.hxx index bb5d5e76e..5b9fa6064 100644 --- a/src/lib/icu/CaseFold.hxx +++ b/src/lib/icu/CaseFold.hxx @@ -23,6 +23,10 @@ #include "check.h" #include "Compiler.h" +#if defined(HAVE_ICU) || defined(_WIN32) +#define HAVE_ICU_CASE_FOLD +#endif + template class AllocatedString; gcc_nonnull_all diff --git a/src/lib/icu/Compare.cxx b/src/lib/icu/Compare.cxx index dc571a316..21b3230bb 100644 --- a/src/lib/icu/Compare.cxx +++ b/src/lib/icu/Compare.cxx @@ -24,18 +24,43 @@ #include +#ifdef HAVE_ICU_CASE_FOLD + IcuCompare::IcuCompare(const char *_needle) noexcept :needle(IcuCaseFold(_needle)) {} +#else + +IcuCompare::IcuCompare(const char *_needle) noexcept + :needle(AllocatedString<>::Duplicate(_needle)) {} + +#endif + bool IcuCompare::operator==(const char *haystack) const noexcept { +#ifdef HAVE_ICU_CASE_FOLD return StringIsEqual(IcuCaseFold(haystack).c_str(), needle.c_str()); +#else + return strcasecmp(haystack, needle.c_str()); +#endif } bool IcuCompare::IsIn(const char *haystack) const noexcept { +#ifdef HAVE_ICU_CASE_FOLD return StringFind(IcuCaseFold(haystack).c_str(), needle.c_str()) != nullptr; +#elif defined(HAVE_STRCASESTR) + return strcasestr(haystack, needle.c_str()) != nullptr; +#else + /* poor man's strcasestr() */ + for (const size_t length = strlen(needle.c_str()); + *haystack != 0; ++haystack) + if (strncasecmp(haystack, needle.c_str(), length) == 0) + return true; + + return false; +#endif }