lib/icu/CaseFold: pass std::string_view

This commit is contained in:
Max Kellermann 2020-04-03 15:38:26 +02:00
parent 09d8e44d56
commit e620677d7c
5 changed files with 9 additions and 13 deletions

View File

@ -45,14 +45,9 @@
#include <string.h> #include <string.h>
AllocatedString<> AllocatedString<>
IcuCaseFold(const char *src) noexcept IcuCaseFold(std::string_view src) noexcept
try { try {
#ifdef HAVE_ICU #ifdef HAVE_ICU
#if !CLANG_CHECK_VERSION(3,6)
/* disabled on clang due to -Wtautological-pointer-compare */
assert(src != nullptr);
#endif
const auto u = UCharFromUTF8(src); const auto u = UCharFromUTF8(src);
if (u.IsNull()) if (u.IsNull())
return AllocatedString<>::Duplicate(src); return AllocatedString<>::Duplicate(src);

View File

@ -25,13 +25,12 @@
#if defined(HAVE_ICU) || defined(_WIN32) #if defined(HAVE_ICU) || defined(_WIN32)
#define HAVE_ICU_CASE_FOLD #define HAVE_ICU_CASE_FOLD
#include "util/Compiler.h" #include <string_view>
template<typename T> class AllocatedString; template<typename T> class AllocatedString;
gcc_nonnull_all
AllocatedString<char> AllocatedString<char>
IcuCaseFold(const char *src) noexcept; IcuCaseFold(std::string_view src) noexcept;
#endif #endif

View File

@ -24,12 +24,12 @@
#ifdef HAVE_ICU_CASE_FOLD #ifdef HAVE_ICU_CASE_FOLD
IcuCompare::IcuCompare(const char *_needle) noexcept IcuCompare::IcuCompare(std::string_view _needle) noexcept
:needle(IcuCaseFold(_needle)) {} :needle(IcuCaseFold(_needle)) {}
#else #else
IcuCompare::IcuCompare(const char *_needle) noexcept IcuCompare::IcuCompare(std::string_view _needle) noexcept
:needle(AllocatedString<>::Duplicate(_needle)) {} :needle(AllocatedString<>::Duplicate(_needle)) {}
#endif #endif

View File

@ -23,6 +23,8 @@
#include "util/Compiler.h" #include "util/Compiler.h"
#include "util/AllocatedString.hxx" #include "util/AllocatedString.hxx"
#include <string_view>
/** /**
* This class can compare one string ("needle") with lots of other * This class can compare one string ("needle") with lots of other
* strings ("haystacks") efficiently, ignoring case. With some * strings ("haystacks") efficiently, ignoring case. With some
@ -34,7 +36,7 @@ class IcuCompare {
public: public:
IcuCompare():needle(nullptr) {} IcuCompare():needle(nullptr) {}
explicit IcuCompare(const char *needle) noexcept; explicit IcuCompare(std::string_view needle) noexcept;
IcuCompare(const IcuCompare &src) noexcept IcuCompare(const IcuCompare &src) noexcept
:needle(src :needle(src

View File

@ -55,7 +55,7 @@ public:
StringFilter(V &&_value, bool _fold_case, bool _substring, bool _negated) StringFilter(V &&_value, bool _fold_case, bool _substring, bool _negated)
:value(std::forward<V>(_value)), :value(std::forward<V>(_value)),
fold_case(_fold_case fold_case(_fold_case
? IcuCompare(value.c_str()) ? IcuCompare(value)
: IcuCompare()), : IcuCompare()),
substring(_substring), negated(_negated) {} substring(_substring), negated(_negated) {}