SongFilter: use class IcuCompare

This commit is contained in:
Max Kellermann 2017-09-20 23:26:38 +02:00
parent d0497dba92
commit 66646d9276
2 changed files with 10 additions and 15 deletions

View File

@ -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());
}

View File

@ -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
*/