Add starts_with to filter expressions
This commit is contained in:
@@ -112,3 +112,32 @@ IcuCompare::IsIn(const char *haystack) const noexcept
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
IcuCompare::StartsWith(const char *haystack) const noexcept
|
||||
{
|
||||
#ifdef HAVE_ICU_CASE_FOLD
|
||||
return StringIsEqual(IcuCaseFold(haystack).c_str(),
|
||||
needle.c_str(), strlen(needle.c_str()));
|
||||
#elif defined(_WIN32)
|
||||
if (needle == nullptr)
|
||||
/* the MultiByteToWideChar() call in the constructor
|
||||
has failed, so let's always fail the comparison */
|
||||
return false;
|
||||
|
||||
try {
|
||||
auto w_haystack = MultiByteToWideChar(CP_UTF8, haystack);
|
||||
return FindNLSStringEx(LOCALE_NAME_INVARIANT,
|
||||
FIND_STARTSWITH|NORM_IGNORECASE,
|
||||
w_haystack.c_str(), -1,
|
||||
needle.c_str(), -1,
|
||||
nullptr,
|
||||
nullptr, nullptr, 0) == 0;
|
||||
} catch (...) {
|
||||
/* MultiByteToWideChar() has failed */
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return strncmp(haystack, needle.c_str(), strlen(needle.c_str()));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -72,6 +72,9 @@ public:
|
||||
|
||||
[[gnu::pure]]
|
||||
bool IsIn(const char *haystack) const noexcept;
|
||||
|
||||
[[gnu::pure]]
|
||||
bool StartsWith(const char *haystack) const noexcept;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user