SongFilter: use std::string
This commit is contained in:
@@ -46,32 +46,43 @@ locate_parse_type(const char *str)
|
|||||||
return tag_name_parse_i(str);
|
return tag_name_parse_i(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
SongFilter::Item::Item(unsigned _tag, const char *_value, bool _fold_case)
|
gcc_pure
|
||||||
:tag(_tag), fold_case(_fold_case),
|
static std::string
|
||||||
value(fold_case
|
CaseFold(const char *p)
|
||||||
? g_utf8_casefold(_value, -1)
|
|
||||||
: g_strdup(_value))
|
|
||||||
{
|
{
|
||||||
|
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
|
bool
|
||||||
SongFilter::Item::StringMatch(const char *s) const
|
SongFilter::Item::StringMatch(const char *s) const
|
||||||
{
|
{
|
||||||
assert(value != nullptr);
|
|
||||||
assert(s != nullptr);
|
assert(s != nullptr);
|
||||||
|
|
||||||
if (fold_case) {
|
if (fold_case) {
|
||||||
char *p = g_utf8_casefold(s, -1);
|
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);
|
g_free(p);
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} 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
|
/* If the search critieron was not visited during the
|
||||||
sweep through the song's tag, it means this field
|
sweep through the song's tag, it means this field
|
||||||
is absent from the tag or empty. Thus, if the
|
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
|
then it's a match as well and we should return
|
||||||
true. */
|
true. */
|
||||||
if (*value == 0)
|
if (value.empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (tag == TAG_ALBUM_ARTIST && visited_types[TAG_ARTIST]) {
|
if (tag == TAG_ALBUM_ARTIST && visited_types[TAG_ARTIST]) {
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -39,21 +40,14 @@ class SongFilter {
|
|||||||
|
|
||||||
bool fold_case;
|
bool fold_case;
|
||||||
|
|
||||||
char *value;
|
std::string value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
gcc_nonnull(3)
|
gcc_nonnull(3)
|
||||||
Item(unsigned tag, const char *value, bool fold_case=false);
|
Item(unsigned tag, const char *value, bool fold_case=false);
|
||||||
|
|
||||||
Item(const Item &other) = delete;
|
Item(const Item &other) = delete;
|
||||||
|
Item(Item &&) = default;
|
||||||
Item(Item &&other)
|
|
||||||
:tag(other.tag), fold_case(other.fold_case),
|
|
||||||
value(other.value) {
|
|
||||||
other.value = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
~Item();
|
|
||||||
|
|
||||||
Item &operator=(const Item &other) = delete;
|
Item &operator=(const Item &other) = delete;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user