SongFilter: use class IcuCompare
This commit is contained in:
@@ -57,17 +57,10 @@ locate_parse_type(const char *str) noexcept
|
|||||||
return tag_name_parse_i(str);
|
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)
|
SongFilter::Item::Item(unsigned _tag, const char *_value, bool _fold_case)
|
||||||
:tag(_tag), fold_case(_fold_case),
|
:tag(_tag),
|
||||||
value(ImportString(_value, _fold_case))
|
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);
|
assert(tag != LOCATE_TAG_MODIFIED_SINCE);
|
||||||
|
|
||||||
if (fold_case) {
|
if (fold_case) {
|
||||||
const auto folded = IcuCaseFold(s);
|
return fold_case.IsIn(s);
|
||||||
assert(!folded.IsNull());
|
|
||||||
return StringFind(folded.c_str(), value.c_str()) != nullptr;
|
|
||||||
} else {
|
} else {
|
||||||
return StringIsEqual(s, value.c_str());
|
return StringIsEqual(s, value.c_str());
|
||||||
}
|
}
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#ifndef MPD_SONG_FILTER_HXX
|
#ifndef MPD_SONG_FILTER_HXX
|
||||||
#define MPD_SONG_FILTER_HXX
|
#define MPD_SONG_FILTER_HXX
|
||||||
|
|
||||||
|
#include "lib/icu/Compare.hxx"
|
||||||
#include "util/AllocatedString.hxx"
|
#include "util/AllocatedString.hxx"
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
@@ -48,10 +49,13 @@ public:
|
|||||||
class Item {
|
class Item {
|
||||||
uint8_t tag;
|
uint8_t tag;
|
||||||
|
|
||||||
bool fold_case;
|
|
||||||
|
|
||||||
AllocatedString<> value;
|
AllocatedString<> value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This value is only set if case folding is enabled.
|
||||||
|
*/
|
||||||
|
IcuCompare fold_case;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For #LOCATE_TAG_MODIFIED_SINCE
|
* For #LOCATE_TAG_MODIFIED_SINCE
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user