1
0
Fork 0

Pkg: nicer Nasal syntax for tags in queries.

This commit is contained in:
James Turner 2014-06-11 18:41:16 +01:00
parent 32f57d0dc1
commit 7a5b729052

View file

@ -168,7 +168,6 @@ static naRef f_package_uninstall(pkg::Package& pkg, const nasal::CallContext& ct
static SGPropertyNode_ptr queryPropsFromHash(const nasal::Hash& h)
{
SGPropertyNode_ptr props(new SGPropertyNode);
int tagCount = 0;
for (nasal::Hash::const_iterator it = h.begin(); it != h.end(); ++it) {
std::string const key = it->getKey();
@ -176,9 +175,14 @@ static SGPropertyNode_ptr queryPropsFromHash(const nasal::Hash& h)
props->setStringValue(key, it->getValue<std::string>());
} else if (strutils::starts_with(key, "rating-")) {
props->setIntValue(key, it->getValue<int>());
} else if (strutils::starts_with(key, "tag-")) {
SGPropertyNode_ptr tag = props->getChild("tag", tagCount++, true);
tag->setStringValue(key.substr(4));
} else if (key == "tags") {
string_list tags = it->getValue<string_list>();
string_list::const_iterator tagIt;
int tagCount = 0;
for (tagIt = tags.begin(); tagIt != tags.end(); ++tagIt) {
SGPropertyNode_ptr tag = props->getChild("tag", tagCount++, true);
tag->setStringValue(*tagIt);
}
} else {
SG_LOG(SG_GENERAL, SG_WARN, "unknown filter term in hash:" << key);
}