diff --git a/src/backend/helpers.cpp b/src/backend/helpers.cpp index 7058c605..10db6aa0 100644 --- a/src/backend/helpers.cpp +++ b/src/backend/helpers.cpp @@ -107,7 +107,7 @@ namespace loot { /// Array used to try each of the expressions defined above using /// an iteration for each of them. - regex version_checks[7] = { + const regex version_checks[7] = { regex(regex1, regex::ECMAScript | regex::icase), regex(regex2, regex::ECMAScript | regex::icase), regex(regex3, regex::ECMAScript | regex::icase), @@ -117,6 +117,9 @@ 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 ////////////////////////////////////////////////////////////////////////// diff --git a/src/backend/helpers.h b/src/backend/helpers.h index 61c2b542..17cb3bcb 100644 --- a/src/backend/helpers.h +++ b/src/backend/helpers.h @@ -36,7 +36,10 @@ namespace loot { /// Array used to try each of the expressions defined using /// an iteration for each of them. - extern std::regex version_checks[7]; + 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 diff --git a/src/backend/metadata.cpp b/src/backend/metadata.cpp index 0ca2e724..e969de8b 100644 --- a/src/backend/metadata.cpp +++ b/src/backend/metadata.cpp @@ -400,47 +400,28 @@ namespace loot { delete file; - string::const_iterator begin, end; - begin = text.begin(); - end = text.end(); - BOOST_LOG_TRIVIAL(trace) << name << ": " << "Attempting to read the version from the description."; for (int j = 0; j < 7 && version.empty(); j++) { smatch what; - while (regex_search(begin, end, what, version_checks[j])) { - if (what.empty()) - continue; - - ssub_match match = what[1]; - if (!match.matched) - continue; - - version = boost::trim_copy(string(match.first, match.second)); + if (regex_search(text, what, version_checks[j])) { + //Use the first sub-expression match. + version = string(what[1].first, what[1].second); break; } } - BOOST_LOG_TRIVIAL(trace) << name << ": " << "Attempting to extract Bash Tags from the description."; - size_t pos1 = text.find("{{BASH:"); - if (pos1 == string::npos || pos1 + 7 == text.length()) - return; - - pos1 += 7; - - size_t pos2 = text.find("}}", pos1); - if (pos2 == string::npos) - return; - - text = text.substr(pos1, pos2-pos1); - - vector 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)); + 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(); + } } + BOOST_LOG_TRIVIAL(trace) << name << ": " << "Plugin loading complete."; } void Plugin::MergeMetadata(const Plugin& plugin) { diff --git a/src/gui/handler.cpp b/src/gui/handler.cpp index 2a7b63d0..4a4d80b2 100644 --- a/src/gui/handler.cpp +++ b/src/gui/handler.cpp @@ -859,6 +859,7 @@ namespace loot { } void Handler::SortPlugins(CefRefPtr frame, CefRefPtr callback) { + BOOST_LOG_TRIVIAL(info) << "Beginning sorting operation."; //Set language. unsigned int language; if (g_app_state.GetSettings()["language"])