From e620677d7ce133214809dccd29c7cec13a34716b Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 3 Apr 2020 15:38:26 +0200
Subject: [PATCH] lib/icu/CaseFold: pass std::string_view

---
 src/lib/icu/CaseFold.cxx  | 7 +------
 src/lib/icu/CaseFold.hxx  | 5 ++---
 src/lib/icu/Compare.cxx   | 4 ++--
 src/lib/icu/Compare.hxx   | 4 +++-
 src/song/StringFilter.hxx | 2 +-
 5 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/lib/icu/CaseFold.cxx b/src/lib/icu/CaseFold.cxx
index b4fe9d8bc..74a0462a2 100644
--- a/src/lib/icu/CaseFold.cxx
+++ b/src/lib/icu/CaseFold.cxx
@@ -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);
diff --git a/src/lib/icu/CaseFold.hxx b/src/lib/icu/CaseFold.hxx
index 294fd1eaf..ba91262d8 100644
--- a/src/lib/icu/CaseFold.hxx
+++ b/src/lib/icu/CaseFold.hxx
@@ -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
 
diff --git a/src/lib/icu/Compare.cxx b/src/lib/icu/Compare.cxx
index dc9ed9093..1fde0a637 100644
--- a/src/lib/icu/Compare.cxx
+++ b/src/lib/icu/Compare.cxx
@@ -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
diff --git a/src/lib/icu/Compare.hxx b/src/lib/icu/Compare.hxx
index 356681f7d..832e7949c 100644
--- a/src/lib/icu/Compare.hxx
+++ b/src/lib/icu/Compare.hxx
@@ -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
diff --git a/src/song/StringFilter.hxx b/src/song/StringFilter.hxx
index 0b170614a..64a23ce44 100644
--- a/src/song/StringFilter.hxx
+++ b/src/song/StringFilter.hxx
@@ -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) {}