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) static SGPropertyNode_ptr queryPropsFromHash(const nasal::Hash& h)
{ {
SGPropertyNode_ptr props(new SGPropertyNode); SGPropertyNode_ptr props(new SGPropertyNode);
int tagCount = 0;
for (nasal::Hash::const_iterator it = h.begin(); it != h.end(); ++it) { for (nasal::Hash::const_iterator it = h.begin(); it != h.end(); ++it) {
std::string const key = it->getKey(); 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>()); props->setStringValue(key, it->getValue<std::string>());
} else if (strutils::starts_with(key, "rating-")) { } else if (strutils::starts_with(key, "rating-")) {
props->setIntValue(key, it->getValue<int>()); props->setIntValue(key, it->getValue<int>());
} else if (strutils::starts_with(key, "tag-")) { } else if (key == "tags") {
SGPropertyNode_ptr tag = props->getChild("tag", tagCount++, true); string_list tags = it->getValue<string_list>();
tag->setStringValue(key.substr(4)); 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 { } else {
SG_LOG(SG_GENERAL, SG_WARN, "unknown filter term in hash:" << key); SG_LOG(SG_GENERAL, SG_WARN, "unknown filter term in hash:" << key);
} }