From 7f0b4852087d9eaa24b0a925e2015a2e67907455 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Tue, 26 Apr 2022 19:39:50 +0100 Subject: [PATCH] Update utils --- premake5.lua | 2 +- src/common/utils/flags.cpp | 14 ++++---------- src/common/utils/info_string.cpp | 8 ++++---- src/common/utils/io.cpp | 2 +- src/common/utils/memory.cpp | 4 ++-- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/premake5.lua b/premake5.lua index ec32492..0831071 100644 --- a/premake5.lua +++ b/premake5.lua @@ -257,7 +257,7 @@ filter {} filter "configurations:Release" optimize "Size" buildoptions {"/GL"} - linkoptions { "/IGNORE:4702", "/LTCG" } + linkoptions {"/IGNORE:4702", "/LTCG"} defines {"NDEBUG"} flags {"FatalCompileWarnings"} filter {} diff --git a/src/common/utils/flags.cpp b/src/common/utils/flags.cpp index 09f1311..a90247a 100644 --- a/src/common/utils/flags.cpp +++ b/src/common/utils/flags.cpp @@ -21,7 +21,8 @@ namespace utils::flags if (wide_flag[0] == L'-') { wide_flag.erase(wide_flag.begin()); - flags.emplace_back(string::convert(wide_flag)); + const auto flag = string::convert(wide_flag); + flags.emplace_back(string::to_lower(flag)); } } @@ -40,14 +41,7 @@ namespace utils::flags parsed = true; } - for (const auto& entry : enabled_flags) - { - if (string::to_lower(entry) == string::to_lower(flag)) - { - return true; - } - } - - return false; + return std::ranges::any_of(enabled_flags.cbegin(), enabled_flags.cend(), + [flag](const auto& elem) { return elem == string::to_lower(flag); }); } } diff --git a/src/common/utils/info_string.cpp b/src/common/utils/info_string.cpp index 039f062..beb3bb8 100644 --- a/src/common/utils/info_string.cpp +++ b/src/common/utils/info_string.cpp @@ -26,7 +26,7 @@ namespace utils return value->second; } - return ""; + return {}; } void info_string::parse(std::string buffer) @@ -49,15 +49,15 @@ namespace utils { //auto first = true; std::string info_string; - for (auto i = this->key_value_pairs_.begin(); i != this->key_value_pairs_.end(); ++i) + for (const auto& [key, val] : this->key_value_pairs_) { //if (first) first = false; /*else*/ info_string.append("\\"); - info_string.append(i->first); // Key + info_string.append(key); info_string.append("\\"); - info_string.append(i->second); // Value + info_string.append(val); } return info_string; diff --git a/src/common/utils/io.cpp b/src/common/utils/io.cpp index b6b636a..24624de 100644 --- a/src/common/utils/io.cpp +++ b/src/common/utils/io.cpp @@ -32,7 +32,7 @@ namespace utils::io if (stream.is_open()) { - stream.write(data.data(), data.size()); + stream.write(data.data(), static_cast(data.size())); stream.close(); return true; } diff --git a/src/common/utils/memory.cpp b/src/common/utils/memory.cpp index 235870a..bda04ae 100644 --- a/src/common/utils/memory.cpp +++ b/src/common/utils/memory.cpp @@ -64,7 +64,7 @@ namespace utils void* memory::allocate(const size_t length) { - return calloc(length, 1); + return std::calloc(length, 1); } char* memory::duplicate_string(const std::string& string) @@ -78,7 +78,7 @@ namespace utils { if (data) { - ::free(data); + std::free(data); } }