aboutsummaryrefslogtreecommitdiffstats
path: root/src/SongFilter.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-29 19:39:17 +0100
committerMax Kellermann <max@duempel.org>2013-10-29 19:39:17 +0100
commita6aa0e4cbf3068ed5a61b7bcef705800caa9fc41 (patch)
treea26a9f6c2be059b596f6f34bd155fe5af623f206 /src/SongFilter.cxx
parent163848ab3b4a1680ba30e167ea19e977c08556f5 (diff)
downloadmpd-a6aa0e4cbf3068ed5a61b7bcef705800caa9fc41.tar.gz
mpd-a6aa0e4cbf3068ed5a61b7bcef705800caa9fc41.tar.xz
mpd-a6aa0e4cbf3068ed5a61b7bcef705800caa9fc41.zip
SongFilter: use std::string
Diffstat (limited to '')
-rw-r--r--src/SongFilter.cxx35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/SongFilter.cxx b/src/SongFilter.cxx
index 62fc8b39f..41f1e0a64 100644
--- a/src/SongFilter.cxx
+++ b/src/SongFilter.cxx
@@ -46,32 +46,43 @@ locate_parse_type(const char *str)
return tag_name_parse_i(str);
}
-SongFilter::Item::Item(unsigned _tag, const char *_value, bool _fold_case)
- :tag(_tag), fold_case(_fold_case),
- value(fold_case
- ? g_utf8_casefold(_value, -1)
- : g_strdup(_value))
+gcc_pure
+static std::string
+CaseFold(const char *p)
{
+ char *q = g_utf8_casefold(p, -1);
+ std::string result(q);
+ g_free(q);
+ return result;
}
-SongFilter::Item::~Item()
+gcc_pure
+static std::string
+ImportString(const char *p, bool fold_case)
+{
+ return fold_case
+ ? CaseFold(p)
+ : std::string(p);
+}
+
+SongFilter::Item::Item(unsigned _tag, const char *_value, bool _fold_case)
+ :tag(_tag), fold_case(_fold_case),
+ value(ImportString(_value, _fold_case))
{
- g_free(value);
}
bool
SongFilter::Item::StringMatch(const char *s) const
{
- assert(value != nullptr);
assert(s != nullptr);
if (fold_case) {
char *p = g_utf8_casefold(s, -1);
- const bool result = strstr(p, value) != NULL;
+ const bool result = strstr(p, value.c_str()) != NULL;
g_free(p);
return result;
} else {
- return strcmp(s, value) == 0;
+ return s == value;
}
}
@@ -99,10 +110,10 @@ SongFilter::Item::Match(const Tag &_tag) const
/* If the search critieron was not visited during the
sweep through the song's tag, it means this field
is absent from the tag or empty. Thus, if the
- searched string is also empty (first char is a \0),
+ searched string is also empty
then it's a match as well and we should return
true. */
- if (*value == 0)
+ if (value.empty())
return true;
if (tag == TAG_ALBUM_ARTIST && visited_types[TAG_ARTIST]) {