mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Replace ilexicographical_compare, iequals usage with locale::to_lower
Using boost::locale::to_lower is less wrong than using the boost::ilexicographical_compare and boost::iequals functions, as the latter don't case fold non-ASCII UTF-8 characters.
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include <thread>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/locale.hpp>
|
||||
|
||||
#include "api/api_database.h"
|
||||
#include "api/helpers/logging.h"
|
||||
@@ -169,7 +170,8 @@ void Game::LoadPlugins(const std::vector<std::string>& plugins,
|
||||
logger->trace("Loading {}", pluginName);
|
||||
}
|
||||
const bool loadHeader =
|
||||
boost::iequals(pluginName, masterFile_) || loadHeadersOnly;
|
||||
loadHeadersOnly ||
|
||||
boost::locale::to_lower(pluginName) == lowercasedMasterFilename_;
|
||||
try {
|
||||
cache_->AddPlugin(Plugin(
|
||||
Type(), cache_, loadOrderHandler_, DataPath() / u8path(pluginName), loadHeader));
|
||||
@@ -209,7 +211,7 @@ std::set<std::shared_ptr<const PluginInterface>> Game::GetLoadedPlugins()
|
||||
}
|
||||
|
||||
void Game::IdentifyMainMasterFile(const std::string& masterFile) {
|
||||
masterFile_ = masterFile;
|
||||
lowercasedMasterFilename_ = boost::locale::to_lower(masterFile);
|
||||
}
|
||||
|
||||
std::vector<std::string> Game::SortPlugins(
|
||||
|
||||
+1
-1
@@ -86,7 +86,7 @@ private:
|
||||
const GameType type_;
|
||||
const std::filesystem::path gamePath_;
|
||||
|
||||
std::string masterFile_;
|
||||
std::string lowercasedMasterFilename_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "loot/metadata/file.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/locale.hpp>
|
||||
|
||||
#include "api/metadata/yaml/file.h"
|
||||
|
||||
@@ -39,11 +39,11 @@ File::File(const std::string& name,
|
||||
ConditionalMetadata(condition) {}
|
||||
|
||||
bool File::operator<(const File& rhs) const {
|
||||
return boost::ilexicographical_compare(GetName(), rhs.GetName());
|
||||
return boost::locale::to_lower(name_) < boost::locale::to_lower(rhs.name_);
|
||||
}
|
||||
|
||||
bool File::operator==(const File& rhs) const {
|
||||
return boost::iequals(GetName(), rhs.GetName());
|
||||
return boost::locale::to_lower(name_) == boost::locale::to_lower(rhs.name_);
|
||||
}
|
||||
|
||||
std::string File::GetName() const { return name_; }
|
||||
|
||||
@@ -276,8 +276,9 @@ bool PluginMetadata::IsRegexPlugin() const {
|
||||
}
|
||||
|
||||
bool PluginMetadata::operator==(const PluginMetadata& rhs) const {
|
||||
if (IsRegexPlugin() == rhs.IsRegexPlugin())
|
||||
return boost::iequals(name_, rhs.GetName());
|
||||
if (IsRegexPlugin() == rhs.IsRegexPlugin()) {
|
||||
return GetLowercasedName() == rhs.GetLowercasedName();
|
||||
}
|
||||
|
||||
if (IsRegexPlugin())
|
||||
return regex_match(rhs.GetName(),
|
||||
@@ -292,11 +293,7 @@ bool PluginMetadata::operator!=(const PluginMetadata& rhs) const {
|
||||
}
|
||||
|
||||
bool PluginMetadata::operator==(const std::string& rhs) const {
|
||||
if (IsRegexPlugin())
|
||||
return regex_match(PluginMetadata(rhs).GetName(),
|
||||
regex(name_, regex::ECMAScript | regex::icase));
|
||||
else
|
||||
return boost::iequals(name_, PluginMetadata(rhs).GetName());
|
||||
return *this == PluginMetadata(rhs);
|
||||
}
|
||||
|
||||
bool PluginMetadata::operator!=(const std::string& rhs) const {
|
||||
|
||||
+1
-1
@@ -263,7 +263,7 @@ uintmax_t Plugin::GetFileSize(std::filesystem::path pluginPath) {
|
||||
}
|
||||
|
||||
bool Plugin::operator<(const Plugin& rhs) const {
|
||||
return boost::ilexicographical_compare(name_, rhs.name_);
|
||||
return GetLowercasedName() < rhs.GetLowercasedName();
|
||||
}
|
||||
|
||||
bool Plugin::IsActive() const { return isActive_; }
|
||||
|
||||
@@ -275,9 +275,10 @@ void PluginSorter::AddPluginVertices(Game& game) {
|
||||
|
||||
bool PluginSorter::GetVertexByName(const std::string& name,
|
||||
vertex_t& vertexOut) const {
|
||||
auto lowercasedName = boost::locale::to_lower(name);
|
||||
for (const auto& vertex :
|
||||
boost::make_iterator_range(boost::vertices(graph_))) {
|
||||
if (boost::iequals(graph_[vertex].GetName(), name)) {
|
||||
if (graph_[vertex].GetLowercasedName() == lowercasedName) {
|
||||
vertexOut = vertex;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user