Reverted use of regex when extracting Bash Tags.

It turns out that it's non-trivial to extract multiple matches from a
repeating sub-group. Fixes #292.
This commit is contained in:
Oliver Hamlet
2014-09-19 12:47:43 +01:00
parent 6a4a344e0e
commit d74116dc69
3 changed files with 16 additions and 15 deletions
-3
View File
@@ -116,9 +116,6 @@ namespace loot {
regex(regex7, regex::ECMAScript | regex::icase)
};
// A regular expression for finding Bash Tags in plugin descriptions.
const regex bash_tag_check("\\{\\{BASH:(?:[ ]*([-A-Za-z.]+)[ ]*,)+[ ]*\\}\\}", regex::ECMAScript | regex::icase);
//////////////////////////////////////////////////////////////////////////
// Helper functions
//////////////////////////////////////////////////////////////////////////
-3
View File
@@ -38,9 +38,6 @@ namespace loot {
/// an iteration for each of them.
extern const std::regex version_checks[7];
// A regular expression for finding Bash Tags in plugin descriptions.
extern const std::regex bash_tag_check;
//////////////////////////////////////////////////////////////////////////
// Helper functions
//////////////////////////////////////////////////////////////////////////
+16 -9
View File
@@ -397,15 +397,22 @@ namespace loot {
}
}
BOOST_LOG_TRIVIAL(trace) << name << ": " << "Attempting to extract Bash Tags from the description.";
smatch results;
if (regex_search(text, results, bash_tag_check)) {
// Regex requires there to be at least one sub-expression match,
// so skip the first (which is the full expression.
for (size_t i = 1; i < results.size(); ++i) {
// Tags in the description must be addition tags, because there's
// nowhere else to remove them from.
auto tag = tags.insert(Tag(string(results[i].first, results[i].second)));
BOOST_LOG_TRIVIAL(trace) << name << ": " << "Extracted Bash Tag: " << tag.first->Name();
size_t pos1 = text.find("{{BASH:");
if (pos1 != string::npos && pos1 + 7 != text.length()) {
pos1 += 7;
size_t pos2 = text.find("}}", pos1);
if (pos2 != string::npos) {
text = text.substr(pos1, pos2 - pos1);
vector<string> bashTags;
boost::split(bashTags, text, boost::is_any_of(","));
for (auto &tag : bashTags) {
boost::trim(tag);
BOOST_LOG_TRIVIAL(trace) << name << ": " << "Extracted Bash Tag: " << tag;
tags.insert(Tag(tag));
}
}
}
}