From 66646d927637b7b370fa81a098d3c35de7a47748 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 20 Sep 2017 23:26:38 +0200
Subject: [PATCH] SongFilter: use class IcuCompare

---
 src/SongFilter.cxx | 17 ++++-------------
 src/SongFilter.hxx |  8 ++++++--
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/src/SongFilter.cxx b/src/SongFilter.cxx
index c761550aa..4c3e746b1 100644
--- a/src/SongFilter.cxx
+++ b/src/SongFilter.cxx
@@ -57,17 +57,10 @@ locate_parse_type(const char *str) noexcept
 	return tag_name_parse_i(str);
 }
 
-static AllocatedString<>
-ImportString(const char *p, bool fold_case)
-{
-	return fold_case
-		? IcuCaseFold(p)
-		: AllocatedString<>::Duplicate(p);
-}
-
 SongFilter::Item::Item(unsigned _tag, const char *_value, bool _fold_case)
-	:tag(_tag), fold_case(_fold_case),
-	 value(ImportString(_value, _fold_case))
+	:tag(_tag),
+	 value(AllocatedString<>::Duplicate(_value)),
+	 fold_case(_fold_case ? IcuCompare(value.c_str()) : IcuCompare())
 {
 }
 
@@ -87,9 +80,7 @@ SongFilter::Item::StringMatch(const char *s) const noexcept
 	assert(tag != LOCATE_TAG_MODIFIED_SINCE);
 
 	if (fold_case) {
-		const auto folded = IcuCaseFold(s);
-		assert(!folded.IsNull());
-		return StringFind(folded.c_str(), value.c_str()) != nullptr;
+		return fold_case.IsIn(s);
 	} else {
 		return StringIsEqual(s, value.c_str());
 	}
diff --git a/src/SongFilter.hxx b/src/SongFilter.hxx
index a0bb25d41..ec8317879 100644
--- a/src/SongFilter.hxx
+++ b/src/SongFilter.hxx
@@ -20,6 +20,7 @@
 #ifndef MPD_SONG_FILTER_HXX
 #define MPD_SONG_FILTER_HXX
 
+#include "lib/icu/Compare.hxx"
 #include "util/AllocatedString.hxx"
 #include "Compiler.h"
 
@@ -48,10 +49,13 @@ public:
 	class Item {
 		uint8_t tag;
 
-		bool fold_case;
-
 		AllocatedString<> value;
 
+		/**
+		 * This value is only set if case folding is enabled.
+		 */
+		IcuCompare fold_case;
+
 		/**
 		 * For #LOCATE_TAG_MODIFIED_SINCE
 		 */