mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Refactor plugin description Bash Tag extraction
This commit is contained in:
+3
-3
@@ -208,7 +208,7 @@ set (LOOT_API_SRC "${CMAKE_BINARY_DIR}/generated/loot_version.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/sorting/plugin_sorting_data.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/crc.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/git_helper.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/version.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/text.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/vertex.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/resource.rc")
|
||||
|
||||
@@ -263,7 +263,7 @@ set (LOOT_API_HEADERS "${CMAKE_SOURCE_DIR}/include/loot/api.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/git_helper.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/crc.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/logging.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/version.h")
|
||||
"${CMAKE_SOURCE_DIR}/src/api/helpers/text.h")
|
||||
|
||||
set (LOOT_TESTS_SRC "${CMAKE_SOURCE_DIR}/src/tests/api/internals/main.cpp")
|
||||
|
||||
@@ -272,7 +272,7 @@ set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/api/internals/game/game_t
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/game/load_order_handler_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/git_helper_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/crc_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/version_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/text_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/helpers/yaml_set_helpers_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/condition_evaluator_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/conditional_metadata_test.h"
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "api/helpers/version.h"
|
||||
#include "api/helpers/text.h"
|
||||
|
||||
#include <regex>
|
||||
|
||||
@@ -62,6 +62,32 @@ const std::vector<regex> versionRegexes({
|
||||
regex::ECMAScript | regex::icase),
|
||||
});
|
||||
|
||||
std::set<Tag> ExtractBashTags(const std::string& description) {
|
||||
std::set<Tag> tags;
|
||||
|
||||
size_t startPos = description.find("{{BASH:");
|
||||
if (startPos == std::string::npos) {
|
||||
return tags;
|
||||
}
|
||||
|
||||
size_t endPos = description.find("}}", startPos);
|
||||
if (endPos == std::string::npos) {
|
||||
return tags;
|
||||
}
|
||||
|
||||
auto commaSeparatedTags = description.substr(startPos, endPos - startPos);
|
||||
|
||||
std::vector<std::string> bashTags;
|
||||
boost::split(bashTags, commaSeparatedTags, [](char c) { return c == ','; });
|
||||
|
||||
for (auto& tag : bashTags) {
|
||||
boost::trim(tag);
|
||||
tags.insert(Tag(tag));
|
||||
}
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
std::optional<std::string> ExtractVersion(const std::string& text) {
|
||||
std::smatch what;
|
||||
for (const auto& versionRegex : versionRegexes) {
|
||||
@@ -22,13 +22,18 @@
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_API_HELPERS_VERSION
|
||||
#define LOOT_API_HELPERS_VERSION
|
||||
#ifndef LOOT_API_HELPERS_TEXT
|
||||
#define LOOT_API_HELPERS_TEXT
|
||||
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "loot/metadata/tag.h"
|
||||
|
||||
namespace loot {
|
||||
std::set<Tag> ExtractBashTags(const std::string& description);
|
||||
|
||||
std::optional<std::string> ExtractVersion(const std::string& text);
|
||||
}
|
||||
|
||||
+2
-24
@@ -25,7 +25,6 @@
|
||||
#include "api/plugin.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <regex>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/locale.hpp>
|
||||
@@ -33,7 +32,7 @@
|
||||
#include "api/game/game.h"
|
||||
#include "api/helpers/crc.h"
|
||||
#include "api/helpers/logging.h"
|
||||
#include "api/helpers/version.h"
|
||||
#include "api/helpers/text.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
|
||||
using std::set;
|
||||
@@ -88,28 +87,7 @@ Plugin::Plugin(const GameType gameType,
|
||||
name_);
|
||||
}
|
||||
|
||||
string text = GetDescription();
|
||||
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 && pos1 != pos2) {
|
||||
text = text.substr(pos1, pos2 - pos1);
|
||||
|
||||
std::vector<string> bashTags;
|
||||
boost::split(bashTags, text, [](char c) { return c == ','; });
|
||||
|
||||
for (auto& tag : bashTags) {
|
||||
boost::trim(tag);
|
||||
tags_.insert(Tag(tag));
|
||||
|
||||
if (logger) {
|
||||
logger->trace("{}: Extracted Bash Tag: {}", name_, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tags_ = ExtractBashTags(GetDescription());
|
||||
|
||||
loadsArchive_ = LoadsArchive(gameType, gameCache, pluginPath);
|
||||
} catch (std::exception& e) {
|
||||
|
||||
+3
-4
@@ -22,10 +22,10 @@ along with LOOT. If not, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_TESTS_API_INTERNALS_HELPERS_VERSION_TEST
|
||||
#define LOOT_TESTS_API_INTERNALS_HELPERS_VERSION_TEST
|
||||
#ifndef LOOT_TESTS_API_INTERNALS_HELPERS_TEXT_TEST
|
||||
#define LOOT_TESTS_API_INTERNALS_HELPERS_TEXT_TEST
|
||||
|
||||
#include "api/helpers/version.h"
|
||||
#include "api/helpers/text.h"
|
||||
#include "loot/loot_version.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
@@ -42,7 +42,6 @@ TEST(Version, shouldExtractAVersionContainingMultipleDigits) {
|
||||
}
|
||||
|
||||
TEST(Version, shouldExtractAVersionContainingMultipleNumbers) {
|
||||
|
||||
EXPECT_EQ("10.11.12.13", ExtractVersion("10.11.12.13").value());
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "tests/api/internals/game/load_order_handler_test.h"
|
||||
#include "tests/api/internals/helpers/crc_test.h"
|
||||
#include "tests/api/internals/helpers/git_helper_test.h"
|
||||
#include "tests/api/internals/helpers/version_test.h"
|
||||
#include "tests/api/internals/helpers/text_test.h"
|
||||
#include "tests/api/internals/helpers/yaml_set_helpers_test.h"
|
||||
#include "tests/api/internals/masterlist_test.h"
|
||||
#include "tests/api/internals/metadata/condition_evaluator_test.h"
|
||||
|
||||
Reference in New Issue
Block a user