lib/icu/CaseFold: pass std::string_view
This commit is contained in:
parent
09d8e44d56
commit
e620677d7c
|
@ -45,14 +45,9 @@
|
|||
#include <string.h>
|
||||
|
||||
AllocatedString<>
|
||||
IcuCaseFold(const char *src) noexcept
|
||||
IcuCaseFold(std::string_view src) noexcept
|
||||
try {
|
||||
#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);
|
||||
if (u.IsNull())
|
||||
return AllocatedString<>::Duplicate(src);
|
||||
|
|
|
@ -25,13 +25,12 @@
|
|||
#if defined(HAVE_ICU) || defined(_WIN32)
|
||||
#define HAVE_ICU_CASE_FOLD
|
||||
|
||||
#include "util/Compiler.h"
|
||||
#include <string_view>
|
||||
|
||||
template<typename T> class AllocatedString;
|
||||
|
||||
gcc_nonnull_all
|
||||
AllocatedString<char>
|
||||
IcuCaseFold(const char *src) noexcept;
|
||||
IcuCaseFold(std::string_view src) noexcept;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
|
||||
#ifdef HAVE_ICU_CASE_FOLD
|
||||
|
||||
IcuCompare::IcuCompare(const char *_needle) noexcept
|
||||
IcuCompare::IcuCompare(std::string_view _needle) noexcept
|
||||
:needle(IcuCaseFold(_needle)) {}
|
||||
|
||||
#else
|
||||
|
||||
IcuCompare::IcuCompare(const char *_needle) noexcept
|
||||
IcuCompare::IcuCompare(std::string_view _needle) noexcept
|
||||
:needle(AllocatedString<>::Duplicate(_needle)) {}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "util/Compiler.h"
|
||||
#include "util/AllocatedString.hxx"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
/**
|
||||
* This class can compare one string ("needle") with lots of other
|
||||
* strings ("haystacks") efficiently, ignoring case. With some
|
||||
|
@ -34,7 +36,7 @@ class IcuCompare {
|
|||
public:
|
||||
IcuCompare():needle(nullptr) {}
|
||||
|
||||
explicit IcuCompare(const char *needle) noexcept;
|
||||
explicit IcuCompare(std::string_view needle) noexcept;
|
||||
|
||||
IcuCompare(const IcuCompare &src) noexcept
|
||||
:needle(src
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
StringFilter(V &&_value, bool _fold_case, bool _substring, bool _negated)
|
||||
:value(std::forward<V>(_value)),
|
||||
fold_case(_fold_case
|
||||
? IcuCompare(value.c_str())
|
||||
? IcuCompare(value)
|
||||
: IcuCompare()),
|
||||
substring(_substring), negated(_negated) {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue