SongFilter: return "const char *" instead of std::string

This commit is contained in:
Max Kellermann 2015-06-25 23:14:40 +02:00
parent c7712e2ef0
commit eb86fdfbea
5 changed files with 18 additions and 15 deletions

View File

@ -300,12 +300,12 @@ SongFilter::HasOtherThanBase() const
return false; return false;
} }
std::string const char *
SongFilter::GetBase() const SongFilter::GetBase() const
{ {
for (const auto &i : items) for (const auto &i : items)
if (i.GetTag() == LOCATE_TAG_BASE_TYPE) if (i.GetTag() == LOCATE_TAG_BASE_TYPE)
return i.GetValue(); return i.GetValue();
return std::string(); return nullptr;
} }

View File

@ -76,8 +76,8 @@ public:
return fold_case; return fold_case;
} }
const std::string &GetValue() const { const char *GetValue() const {
return value; return value.c_str();
} }
gcc_pure gcc_nonnull(2) gcc_pure gcc_nonnull(2)
@ -149,11 +149,11 @@ public:
bool HasOtherThanBase() const; bool HasOtherThanBase() const;
/** /**
* Returns the "base" specification (if there is one) or an * Returns the "base" specification (if there is one) or
* empty string. * nullptr.
*/ */
gcc_pure gcc_pure
std::string GetBase() const; const char *GetBase() const;
}; };
/** /**

View File

@ -26,8 +26,11 @@ DatabaseSelection::DatabaseSelection(const char *_uri, bool _recursive,
{ {
/* optimization: if the caller didn't specify a base URI, pick /* optimization: if the caller didn't specify a base URI, pick
the one from SongFilter */ the one from SongFilter */
if (uri.empty() && filter != nullptr) if (uri.empty() && filter != nullptr) {
uri = filter->GetBase(); auto base = filter->GetBase();
if (base != nullptr)
uri = base;
}
} }
bool bool

View File

@ -263,18 +263,18 @@ SendConstraints(mpd_connection *connection, const SongFilter::Item &item)
return mpd_search_add_base_constraint(connection, return mpd_search_add_base_constraint(connection,
MPD_OPERATOR_DEFAULT, MPD_OPERATOR_DEFAULT,
item.GetValue().c_str()); item.GetValue());
#endif #endif
case LOCATE_TAG_FILE_TYPE: case LOCATE_TAG_FILE_TYPE:
return mpd_search_add_uri_constraint(connection, return mpd_search_add_uri_constraint(connection,
MPD_OPERATOR_DEFAULT, MPD_OPERATOR_DEFAULT,
item.GetValue().c_str()); item.GetValue());
case LOCATE_TAG_ANY_TYPE: case LOCATE_TAG_ANY_TYPE:
return mpd_search_add_any_tag_constraint(connection, return mpd_search_add_any_tag_constraint(connection,
MPD_OPERATOR_DEFAULT, MPD_OPERATOR_DEFAULT,
item.GetValue().c_str()); item.GetValue());
default: default:
tag = Convert(TagType(item.GetTag())); tag = Convert(TagType(item.GetTag()));
@ -284,7 +284,7 @@ SendConstraints(mpd_connection *connection, const SongFilter::Item &item)
return mpd_search_add_tag_constraint(connection, return mpd_search_add_tag_constraint(connection,
MPD_OPERATOR_DEFAULT, MPD_OPERATOR_DEFAULT,
tag, tag,
item.GetValue().c_str()); item.GetValue());
} }
} }

View File

@ -303,7 +303,7 @@ UpnpDatabase::SearchSongs(const ContentDirectoryService &server,
} else { } else {
cond += " = "; cond += " = ";
} }
dquote(cond, item.GetValue().c_str()); dquote(cond, item.GetValue());
} }
cond += ')'; cond += ')';
} }
@ -339,7 +339,7 @@ UpnpDatabase::SearchSongs(const ContentDirectoryService &server,
} else { } else {
cond += " = "; cond += " = ";
} }
dquote(cond, item.GetValue().c_str()); dquote(cond, item.GetValue());
} }
} }