mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Updated plugin description Bash Tag extraction.
Now uses regex matching, which is easier to read and shouldn't provide any real performance hit. Also added a few more debug logging statements, and tidied up version matching too.
This commit is contained in:
@@ -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
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -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
|
||||
|
||||
+14
-33
@@ -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<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));
|
||||
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) {
|
||||
|
||||
@@ -859,6 +859,7 @@ namespace loot {
|
||||
}
|
||||
|
||||
void Handler::SortPlugins(CefRefPtr<CefFrame> frame, CefRefPtr<Callback> callback) {
|
||||
BOOST_LOG_TRIVIAL(info) << "Beginning sorting operation.";
|
||||
//Set language.
|
||||
unsigned int language;
|
||||
if (g_app_state.GetSettings()["language"])
|
||||
|
||||
Reference in New Issue
Block a user