From 0c8df973aa0c07b5676b306ff0c83af2c5f207ce Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 31 Mar 2025 20:31:32 +0100 Subject: [PATCH] Convert some internal functions to take std::string_view --- src/api/game/game.cpp | 2 +- src/api/game/game_cache.cpp | 2 +- src/api/game/game_cache.h | 3 ++- src/api/game/load_order_handler.cpp | 14 +++++----- src/api/game/load_order_handler.h | 3 ++- src/api/helpers/text.cpp | 22 ++++++++-------- src/api/helpers/text.h | 13 +++++----- src/api/metadata/condition_evaluator.cpp | 14 +++++----- src/api/metadata/condition_evaluator.h | 3 ++- src/api/metadata/plugin_metadata.cpp | 7 +++-- src/api/metadata_list.cpp | 11 +++----- src/api/metadata_list.h | 3 ++- src/api/plugin.cpp | 27 ++++++++++---------- src/api/plugin.h | 5 ++-- src/api/sorting/group_sort.cpp | 8 +++--- src/api/sorting/group_sort.h | 5 ++-- src/api/sorting/plugin_graph.cpp | 5 ++-- src/api/sorting/plugin_sort.cpp | 10 ++++---- src/api/sorting/plugin_sort.h | 1 + src/tests/api/internals/metadata_list_test.h | 20 +++++++-------- src/tests/api/internals/plugin_test.h | 4 +-- src/tests/common_game_test_fixture.h | 2 +- 22 files changed, 96 insertions(+), 88 deletions(-) diff --git a/src/api/game/game.cpp b/src/api/game/game.cpp index 25d8112a..940f1ca0 100644 --- a/src/api/game/game.cpp +++ b/src/api/game/game.cpp @@ -139,7 +139,7 @@ std::filesystem::path ResolvePluginPath( std::vector FindArchives( const std::filesystem::path& parentPath, - const std::string& archiveFileExtension) { + std::string_view archiveFileExtension) { if (!std::filesystem::is_directory(parentPath)) { return {}; } diff --git a/src/api/game/game_cache.cpp b/src/api/game/game_cache.cpp index a00b3c85..c6b90bce 100644 --- a/src/api/game/game_cache.cpp +++ b/src/api/game/game_cache.cpp @@ -36,7 +36,7 @@ std::vector GameCache::GetPlugins() const { return output; } -const Plugin* GameCache::GetPlugin(const std::string& pluginName) const { +const Plugin* GameCache::GetPlugin(std::string_view pluginName) const { const auto it = plugins_.find(NormalizeFilename(pluginName)); if (it != end(plugins_)) return it->second.get(); diff --git a/src/api/game/game_cache.h b/src/api/game/game_cache.h index af70a17f..9078d59f 100644 --- a/src/api/game/game_cache.h +++ b/src/api/game/game_cache.h @@ -26,6 +26,7 @@ #define LOOT_API_GAME_GAME_CACHE #include +#include #include #include "api/plugin.h" @@ -34,7 +35,7 @@ namespace loot { class GameCache { public: std::vector GetPlugins() const; - const Plugin* GetPlugin(const std::string& pluginName) const; + const Plugin* GetPlugin(std::string_view pluginName) const; void AddPlugin(Plugin&& plugin); std::vector GetPluginsWithReplacements( diff --git a/src/api/game/load_order_handler.cpp b/src/api/game/load_order_handler.cpp index 44293f80..aca230c6 100644 --- a/src/api/game/load_order_handler.cpp +++ b/src/api/game/load_order_handler.cpp @@ -210,7 +210,8 @@ std::filesystem::path LoadOrderHandler::GetActivePluginsFilePath() const { return filePath; } -std::vector LoadOrderHandler::GetAdditionalDataPaths() const { +std::vector LoadOrderHandler::GetAdditionalDataPaths() + const { const auto logger = getLogger(); if (logger) { logger->trace("Getting additional data paths."); @@ -219,7 +220,8 @@ std::vector LoadOrderHandler::GetAdditionalDataPaths() co char** pathArr = nullptr; size_t pathArrSize = 0; - const unsigned int ret = lo_get_additional_plugins_directories(gh_.get(), &pathArr, &pathArrSize); + const unsigned int ret = + lo_get_additional_plugins_directories(gh_.get(), &pathArr, &pathArrSize); HandleError("get additional data paths", ret); @@ -288,7 +290,7 @@ void LoadOrderHandler::SetAdditionalDataPaths( } } -void LoadOrderHandler::HandleError(const std::string& operation, +void LoadOrderHandler::HandleError(std::string_view operation, unsigned int returnCode) const { if (returnCode == LIBLO_OK || returnCode == LIBLO_WARN_LO_MISMATCH) { return; @@ -298,10 +300,10 @@ void LoadOrderHandler::HandleError(const std::string& operation, std::string err; lo_get_error_message(&e); if (e == nullptr) { - err = "libloadorder failed to " + operation + - ". Details could not be fetched."; + err = fmt::format( + "libloadorder failed to {}. Details could not be fetched.", operation); } else { - err = "libloadorder failed to " + operation + ". Details: " + e; + err = fmt::format("libloadorder failed to {}. Details: {}", operation, e); } auto logger = getLogger(); diff --git a/src/api/game/load_order_handler.h b/src/api/game/load_order_handler.h index ae5aa9b9..5273773a 100644 --- a/src/api/game/load_order_handler.h +++ b/src/api/game/load_order_handler.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "loot/enum/game_type.h" @@ -61,7 +62,7 @@ public: const std::vector& dataPaths) const; private: - void HandleError(const std::string& operation, unsigned int returnCode) const; + void HandleError(std::string_view operation, unsigned int returnCode) const; std::unique_ptr::type, decltype(&lo_destroy_handle)> diff --git a/src/api/helpers/text.cpp b/src/api/helpers/text.cpp index 3a157212..dd77107d 100644 --- a/src/api/helpers/text.cpp +++ b/src/api/helpers/text.cpp @@ -55,7 +55,7 @@ constexpr const char* pseudosemVersionRegex = 'v' or 'version:. */ constexpr const char* digitsVersionRegex = R"((?:^|v|version:\s*)(\d+))"; -std::vector ExtractBashTags(const std::string& description) { +std::vector ExtractBashTags(std::string_view description) { std::vector tags; static constexpr const char* BASH_TAGS_OPENER = "{{BASH:"; @@ -87,7 +87,7 @@ std::vector ExtractBashTags(const std::string& description) { return tags; } -std::optional ExtractVersion(const std::string& text) { +std::optional ExtractVersion(std::string_view text) { using std::regex; /* There are a few different version formats that can appear in strings @@ -102,9 +102,9 @@ std::optional ExtractVersion(const std::string& text) { regex(digitsVersionRegex, regex::ECMAScript | regex::icase), }); - std::smatch what; + std::match_results what; for (const auto& versionRegex : versionRegexes) { - if (std::regex_search(text, what, versionRegex)) { + if (std::regex_search(text.begin(), text.end(), what, versionRegex)) { for (auto it = next(begin(what)); it != end(what); ++it) { if (it->str().empty()) continue; @@ -135,9 +135,9 @@ int narrow(size_t value) { return castValue; } -std::wstring ToWinWide(const std::string& str) { +std::wstring ToWinWide(std::string_view str) { const size_t len = MultiByteToWideChar( - CP_UTF8, 0, str.c_str(), static_cast(str.length()), 0, 0); + CP_UTF8, 0, str.data(), static_cast(str.length()), 0, 0); if (len == 0) { return std::wstring(); @@ -146,7 +146,7 @@ std::wstring ToWinWide(const std::string& str) { std::wstring wstr(len, 0); MultiByteToWideChar(CP_UTF8, 0, - str.c_str(), + str.data(), narrow(str.length()), wstr.data(), narrow(wstr.length())); @@ -180,7 +180,7 @@ std::string FromWinWide(const std::wstring& wstr) { } #endif -ComparableFilename ToComparableFilename(const std::string filename) { +ComparableFilename ToComparableFilename(std::string_view filename) { #ifdef _WIN32 return ToWinWide(filename); #else @@ -188,7 +188,7 @@ ComparableFilename ToComparableFilename(const std::string filename) { #endif } -int CompareFilenames(const std::string& lhs, const std::string& rhs) { +int CompareFilenames(std::string_view lhs, std::string_view rhs) { return CompareFilenames(ToComparableFilename(lhs), ToComparableFilename(rhs)); } @@ -216,7 +216,7 @@ int CompareFilenames(const ComparableFilename& lhs, #endif } -std::string NormalizeFilename(const std::string& filename) { +std::string NormalizeFilename(std::string_view filename) { #ifdef _WIN32 auto wideString = ToWinWide(filename); @@ -235,7 +235,7 @@ std::string NormalizeFilename(const std::string& filename) { #endif } -std::string TrimDotGhostExtension(const std::string& filename) { +std::string TrimDotGhostExtension(std::string&& filename) { // If the name passed ends in '.ghost', that should be trimmed. if (boost::iends_with(filename, GHOST_FILE_EXTENSION)) { return filename.substr(0, filename.length() - GHOST_FILE_EXTENSION_LENGTH); diff --git a/src/api/helpers/text.h b/src/api/helpers/text.h index f3b0b50e..373cdfdb 100644 --- a/src/api/helpers/text.h +++ b/src/api/helpers/text.h @@ -27,6 +27,7 @@ #include #include +#include #include #include "loot/metadata/tag.h" @@ -47,17 +48,17 @@ typedef std::wstring ComparableFilename; typedef icu::UnicodeString ComparableFilename; #endif -std::vector ExtractBashTags(const std::string& description); +std::vector ExtractBashTags(std::string_view description); -std::optional ExtractVersion(const std::string& text); +std::optional ExtractVersion(std::string_view text); -ComparableFilename ToComparableFilename(const std::string filename); +ComparableFilename ToComparableFilename(std::string_view filename); // Compare strings as if they're filenames, respecting filesystem case // insensitivity on Windows. Returns -1 if lhs < rhs, 0 if lhs == rhs, and 1 if // lhs > rhs. The comparison may give different results on Linux, but is still // locale-invariant. -int CompareFilenames(const std::string& lhs, const std::string& rhs); +int CompareFilenames(std::string_view lhs, std::string_view rhs); int CompareFilenames(const ComparableFilename& lhs, const ComparableFilename& rhs); @@ -68,9 +69,9 @@ int CompareFilenames(const ComparableFilename& lhs, // different but hopefully still consistent enough with the behaviour on Windows // that the normalized filenames distinguish characters in a similar way to the // Windows filesystem. -std::string NormalizeFilename(const std::string& filename); +std::string NormalizeFilename(std::string_view filename); -std::string TrimDotGhostExtension(const std::string& filename); +std::string TrimDotGhostExtension(std::string&& filename); } #endif diff --git a/src/api/metadata/condition_evaluator.cpp b/src/api/metadata/condition_evaluator.cpp index 62c42a25..f933dedb 100644 --- a/src/api/metadata/condition_evaluator.cpp +++ b/src/api/metadata/condition_evaluator.cpp @@ -32,18 +32,18 @@ #include "loot/exception/error_categories.h" namespace loot { -void HandleError(const std::string operation, int returnCode) { +void HandleError(std::string_view operation, int returnCode) { if (returnCode == LCI_OK) { return; } const char* message = nullptr; - std::string err = "Failed to " + operation + ". "; + std::string err; lci_get_error_message(&message); if (message == nullptr) { - err += "Error code: " + std::to_string(returnCode); + err = fmt::format("Failed to {}. Error code: {}", operation, returnCode); } else { - err += "Details: " + std::string(message); + err = fmt::format("Failed to {}. Details: {}", operation, message); } auto logger = getLogger(); @@ -260,12 +260,12 @@ void ConditionEvaluator::SetAdditionalDataPaths( } bool ConditionEvaluator::Evaluate(const PluginCleaningData& cleaningData, - const std::string& pluginName) { + std::string_view pluginName) { if (pluginName.empty()) return false; - return Evaluate("checksum(\"" + pluginName + "\", " + - CrcToString(cleaningData.GetCRC()) + ")"); + return Evaluate(fmt::format( + "checksum(\"{}\", {})", pluginName, CrcToString(cleaningData.GetCRC()))); } void ParseCondition(const std::string& condition) { diff --git a/src/api/metadata/condition_evaluator.h b/src/api/metadata/condition_evaluator.h index ad1c33cb..4024bbd4 100644 --- a/src/api/metadata/condition_evaluator.h +++ b/src/api/metadata/condition_evaluator.h @@ -30,6 +30,7 @@ #include #include #include +#include #include "loot/enum/game_type.h" #include "loot/metadata/plugin_cleaning_data.h" @@ -56,7 +57,7 @@ public: private: bool Evaluate(const PluginCleaningData& cleaningData, - const std::string& pluginName); + std::string_view pluginName); std::unique_ptr lciState_; }; diff --git a/src/api/metadata/plugin_metadata.cpp b/src/api/metadata/plugin_metadata.cpp index 9737d7d9..ce880e62 100644 --- a/src/api/metadata/plugin_metadata.cpp +++ b/src/api/metadata/plugin_metadata.cpp @@ -50,10 +50,9 @@ std::vector mergeVectors(std::vector first, } namespace loot { -PluginMetadata::PluginMetadata(const std::string& n) : name_(n) { - // If the name passed ends in '.ghost', that should be trimmed. - name_ = TrimDotGhostExtension(n); - +// If the name passed ends in '.ghost', that should be trimmed. +PluginMetadata::PluginMetadata(const std::string& n) : + name_(TrimDotGhostExtension(std::string(n))) { if (IsRegexPlugin()) { nameRegex_ = std::regex(name_, std::regex::ECMAScript | std::regex::icase); } diff --git a/src/api/metadata_list.cpp b/src/api/metadata_list.cpp index 9cfcea50..53a090cc 100644 --- a/src/api/metadata_list.cpp +++ b/src/api/metadata_list.cpp @@ -56,7 +56,7 @@ std::string read_to_string(const std::filesystem::path& filePath) { } std::optional> FindPreludeBounds( - const std::string& masterlist) { + std::string_view masterlist) { size_t startOfPrelude = std::string::npos; size_t endOfPrelude = std::string::npos; @@ -118,7 +118,7 @@ std::string IndentPrelude(const std::string& prelude) { } std::string ReplaceMetadataListPrelude(const std::string& prelude, - const std::string& masterlist) { + std::string&& masterlist) { auto preludeBounds = FindPreludeBounds(masterlist); if (!preludeBounds.has_value()) { @@ -163,11 +163,8 @@ void MetadataList::LoadWithPrelude(const std::filesystem::path& filePath, // retained. // As such, replacing the prelude needs to happen before parsing, // which means reading the files and performing string manipulation. - auto prelude_content = read_to_string(preludePath); - auto masterlist_content = read_to_string(filePath); - - masterlist_content = - ReplaceMetadataListPrelude(prelude_content, masterlist_content); + auto masterlist_content = ReplaceMetadataListPrelude( + read_to_string(preludePath), read_to_string(filePath)); auto stream = std::istringstream(masterlist_content); this->Load(stream, filePath); diff --git a/src/api/metadata_list.h b/src/api/metadata_list.h index 44146691..3d3ca8f0 100644 --- a/src/api/metadata_list.h +++ b/src/api/metadata_list.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -51,7 +52,7 @@ namespace loot { // YAML's block style (at least up to the end of the prelude in the // latter). This is true for all official files. std::string ReplaceMetadataListPrelude(const std::string& prelude, - const std::string& masterlist); + std::string&& masterlist); class MetadataList { public: diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index e4298ae9..d248769c 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -37,17 +37,20 @@ #include "loot/exception/file_access_error.h" namespace loot { +// Intentionally takes a copy of the first parameter. std::filesystem::path ReplaceExtension(std::filesystem::path path, - const std::string& newExtension) { + std::string_view newExtension) { return path.replace_extension(std::filesystem::u8path(newExtension)); } +// Intentionally takes a copy of the first parameter. std::filesystem::path GetSuffixedArchivePath(std::filesystem::path pluginPath, - const std::string& suffix, - const std::string& newExtension) { + std::string_view suffix, + std::string_view newExtension) { // replace_extension() with no argument just removes the existing extension. pluginPath.replace_extension(); - pluginPath += suffix + newExtension; + pluginPath += suffix; + pluginPath += newExtension; return pluginPath; } @@ -89,7 +92,7 @@ std::vector FindAssociatedArchive( std::vector FindAssociatedArchivesWithSuffixes( const std::filesystem::path& pluginPath, - const std::string& archiveExtension, + std::string_view archiveExtension, const std::vector& supportedSuffixes) { std::vector paths; @@ -181,14 +184,12 @@ std::vector FindAssociatedArchives( } } -void HandleEspluginError(unsigned int returnCode, - const std::string& operation) { +void HandleEspluginError(unsigned int returnCode, std::string_view operation) { if (returnCode == ESP_OK) { return; } - auto err = "esplugin failed to " + operation + - ". Error code: " + std::to_string(returnCode); + auto err = fmt::format("esplugin failed to {}. Error code: {}", operation, returnCode); const char* e = nullptr; esp_get_error_message(&e); @@ -207,8 +208,8 @@ void HandleEspluginError(unsigned int returnCode, } void HandleEspluginError(unsigned int returnCode, - const std::string& message, - const std::string& args...) { + std::string_view message, + std::string_view args...) { if (returnCode == ESP_OK) { return; } @@ -228,7 +229,7 @@ void HandleEspluginError(unsigned int returnCode, Plugin::Plugin(const GameType gameType, const GameCache& gameCache, - std::filesystem::path pluginPath, + const std::filesystem::path& pluginPath, const bool headerOnly) : name_(gameType == GameType::openmw ? pluginPath.filename().u8string() @@ -655,7 +656,7 @@ unsigned int Plugin::GetEspluginGameId(GameType gameType) { } } -bool hasPluginFileExtension(std::string filename, GameType gameType) { +bool hasPluginFileExtension(std::string_view filename, GameType gameType) { if (gameType != GameType::openmw && boost::iends_with(filename, GHOST_FILE_EXTENSION)) { filename = diff --git a/src/api/plugin.h b/src/api/plugin.h index 5c741eec..c1e540b6 100644 --- a/src/api/plugin.h +++ b/src/api/plugin.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "api/game/load_order_handler.h" @@ -53,7 +54,7 @@ class Plugin final : public PluginSortingInterface { public: explicit Plugin(const GameType gameType, const GameCache& gameCache, - std::filesystem::path pluginPath, + const std::filesystem::path& pluginPath, const bool headerOnly); void ResolveRecordIds(Vec_PluginMetadata* pluginsMetadata) const; @@ -116,7 +117,7 @@ private: std::string GetArchiveFileExtension(const GameType gameType); -bool hasPluginFileExtension(std::string filename, GameType gameType); +bool hasPluginFileExtension(std::string_view filename, GameType gameType); bool equivalent(const std::filesystem::path& path1, const std::filesystem::path& path2); diff --git a/src/api/sorting/group_sort.cpp b/src/api/sorting/group_sort.cpp index 02d02075..eb4f58bc 100644 --- a/src/api/sorting/group_sort.cpp +++ b/src/api/sorting/group_sort.cpp @@ -171,7 +171,7 @@ GroupGraph BuildGroupGraph(const std::vector& masterlistGroups, return graph; } -vertex_t GetVertexByName(const GroupGraph& graph, const std::string& name) { +vertex_t GetVertexByName(const GroupGraph& graph, std::string_view name) { for (const auto& vertex : boost::make_iterator_range(boost::vertices(graph))) { if (graph[vertex] == name) { @@ -184,12 +184,12 @@ vertex_t GetVertexByName(const GroupGraph& graph, const std::string& name) { logger->error("Can't find group with name \"{}\"", name); } - throw std::invalid_argument("Can't find group with name \"" + name + "\""); + throw std::invalid_argument("Can't find group with name \"" + std::string(name) + "\""); } std::vector GetGroupsPath(const GroupGraph& graph, - const std::string& fromGroupName, - const std::string& toGroupName) { + std::string_view fromGroupName, + std::string_view toGroupName) { auto logger = getLogger(); auto fromVertex = GetVertexByName(graph, fromGroupName); diff --git a/src/api/sorting/group_sort.h b/src/api/sorting/group_sort.h index fa27ed3d..776251ce 100644 --- a/src/api/sorting/group_sort.h +++ b/src/api/sorting/group_sort.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -45,7 +46,7 @@ GroupGraph BuildGroupGraph(const std::vector& masterlistGroups, const std::vector& userGroups); std::vector GetGroupsPath(const GroupGraph& groupGraph, - const std::string& fromGroupName, - const std::string& toGroupName); + std::string_view fromGroupName, + std::string_view toGroupName); } #endif diff --git a/src/api/sorting/plugin_graph.cpp b/src/api/sorting/plugin_graph.cpp index 8d7ae96a..28301b1c 100644 --- a/src/api/sorting/plugin_graph.cpp +++ b/src/api/sorting/plugin_graph.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "api/helpers/logging.h" #include "api/helpers/text.h" @@ -918,11 +919,11 @@ void PluginGraph::AddHardcodedPluginEdges( // Build the vertex map for implicitly active plugins and record the vertices // for other plugins. for (const auto& vertex : boost::make_iterator_range(GetVertices())) { - const auto pluginName = GetPlugin(vertex).GetName(); + const auto& pluginName = GetPlugin(vertex).GetName(); const auto it = std::find_if(hardcodedPlugins.begin(), hardcodedPlugins.end(), - [&](const std::string& name) { + [&](std::string_view name) { return CompareFilenames(name, pluginName) == 0; }); diff --git a/src/api/sorting/plugin_sort.cpp b/src/api/sorting/plugin_sort.cpp index 8dc545db..35095f5b 100644 --- a/src/api/sorting/plugin_sort.cpp +++ b/src/api/sorting/plugin_sort.cpp @@ -48,8 +48,8 @@ std::vector GetPluginsSortingData( const auto userMetadata = db.GetPluginUserMetadata(pluginFilename, true) .value_or(PluginMetadata(pluginFilename)); - const auto pluginSortingData = PluginSortingData( - plugin, masterlistMetadata, userMetadata, i); + const auto pluginSortingData = + PluginSortingData(plugin, masterlistMetadata, userMetadata, i); pluginsSortingData.push_back(pluginSortingData); i += 1; @@ -77,7 +77,7 @@ void ValidatePluginGroups(const std::vector& plugins, bool IsInRange(const std::vector::const_iterator& begin, const std::vector::const_iterator& end, - const std::string& name) { + std::string_view name) { return std::any_of(begin, end, [&](const PluginSortingData& plugin) { return CompareFilenames(plugin.GetName(), name) == 0; }); @@ -91,10 +91,10 @@ void ValidateSpecificAndHardcodedEdges( const std::vector& hardcodedPlugins) { const auto logger = getLogger(); - const auto isNonMaster = [&](const std::string& name) { + const auto isNonMaster = [&](std::string_view name) { return IsInRange(firstNonMaster, end, name); }; - const auto isBlueprintMaster = [&](const std::string& name) { + const auto isBlueprintMaster = [&](std::string_view name) { return IsInRange(firstBlueprintMaster, firstNonMaster, name); }; diff --git a/src/api/sorting/plugin_sort.h b/src/api/sorting/plugin_sort.h index a905f2e2..56850643 100644 --- a/src/api/sorting/plugin_sort.h +++ b/src/api/sorting/plugin_sort.h @@ -26,6 +26,7 @@ #define LOOT_API_SORTING_PLUGIN_SORT #include +#include #include #include "api/game/game.h" diff --git a/src/tests/api/internals/metadata_list_test.h b/src/tests/api/internals/metadata_list_test.h index 61804644..ea618dde 100644 --- a/src/tests/api/internals/metadata_list_test.h +++ b/src/tests/api/internals/metadata_list_test.h @@ -452,7 +452,7 @@ TEST(ReplaceMetadataListPrelude, shouldReturnAnEmptyStringIfGivenEmptyStrings) { std::string prelude = ""; std::string masterlist = ""; - auto result = ReplaceMetadataListPrelude(prelude, masterlist); + auto result = ReplaceMetadataListPrelude(prelude, std::string(masterlist)); EXPECT_EQ(masterlist, result); } @@ -466,7 +466,7 @@ TEST(ReplaceMetadataListPrelude, shouldNotChangeAMasterlistWithNoPrelude) { - name: a.esp )"; - auto result = ReplaceMetadataListPrelude(prelude, masterlist); + auto result = ReplaceMetadataListPrelude(prelude, std::string(masterlist)); EXPECT_EQ(masterlist, result); } @@ -484,7 +484,7 @@ plugins: - name: a.esp )"; - auto result = ReplaceMetadataListPrelude(prelude, masterlist); + auto result = ReplaceMetadataListPrelude(prelude, std::move(masterlist)); auto expectedResult = R"(prelude: globals: @@ -510,7 +510,7 @@ prelude: )"; - auto result = ReplaceMetadataListPrelude(prelude, masterlist); + auto result = ReplaceMetadataListPrelude(prelude, std::move(masterlist)); auto expectedResult = R"(plugins: - name: a.esp @@ -540,7 +540,7 @@ plugins: - name: a.esp )"; - auto result = ReplaceMetadataListPrelude(prelude, masterlist); + auto result = ReplaceMetadataListPrelude(prelude, std::move(masterlist)); auto expectedResult = R"( common: @@ -573,7 +573,7 @@ plugins: - name: a.esp )"; - auto result = ReplaceMetadataListPrelude(prelude, masterlist); + auto result = ReplaceMetadataListPrelude(prelude, std::move(masterlist)); auto expectedResult = R"(prelude: globals: @@ -597,7 +597,7 @@ plugins: - name: a.esp )"; - auto result = ReplaceMetadataListPrelude(prelude, masterlist); + auto result = ReplaceMetadataListPrelude(prelude, std::move(masterlist)); auto expectedResult = R"(prelude: globals: [{type: note, content: A message.}] @@ -612,7 +612,7 @@ TEST(ReplaceMetadataListPrelude, doesNotChangeAFlowStyleMasterlist) { std::string prelude = "globals: [{type: note, content: A message.}]"; std::string masterlist = "{prelude: {}, plugins: [{name: a.esp}]}"; - auto result = ReplaceMetadataListPrelude(prelude, masterlist); + auto result = ReplaceMetadataListPrelude(prelude, std::string(masterlist)); EXPECT_EQ(masterlist, result); } @@ -631,7 +631,7 @@ plugins: - name: a.esp )"; - auto result = ReplaceMetadataListPrelude(prelude, masterlist); + auto result = ReplaceMetadataListPrelude(prelude, std::move(masterlist)); auto expectedResult = R"(prelude: globals: @@ -658,7 +658,7 @@ plugins: - name: a.esp )"; - auto result = ReplaceMetadataListPrelude(prelude, masterlist); + auto result = ReplaceMetadataListPrelude(prelude, std::move(masterlist)); auto expectedResult = R"(prelude: globals: diff --git a/src/tests/api/internals/plugin_test.h b/src/tests/api/internals/plugin_test.h index 1470a861..fe250cea 100644 --- a/src/tests/api/internals/plugin_test.h +++ b/src/tests/api/internals/plugin_test.h @@ -150,7 +150,7 @@ class TestPlugin : public PluginSortingInterface { public: TestPlugin() : name_("") {} - TestPlugin(const std::string& name) : name_(name) {} + TestPlugin(std::string_view name) : name_(name) {} std::string GetName() const override { return name_; } @@ -208,7 +208,7 @@ public: otherPlugin->assetsOverlapWith.count(this) != 0; } - void AddMaster(const std::string& master) { masters_.push_back(master); } + void AddMaster(std::string_view master) { masters_.push_back(std::string(master)); } void SetIsMaster(bool isMaster) { isMaster_ = isMaster; } diff --git a/src/tests/common_game_test_fixture.h b/src/tests/common_game_test_fixture.h index 9658b551..f5ffd0f6 100644 --- a/src/tests/common_game_test_fixture.h +++ b/src/tests/common_game_test_fixture.h @@ -186,7 +186,7 @@ protected: } void copyPlugin(const std::filesystem::path& sourceParentPath, - const std::string& filename) { + std::string_view filename) { std::filesystem::copy_file(sourceParentPath / filename, dataPath / filename); ASSERT_TRUE(std::filesystem::exists(dataPath / filename));