From 826e2bbf98ca5c6088c3d19968272b29fc335972 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:23:58 -0700 Subject: [PATCH] StringUtil: More Wrappers For `Common::IsLower(char)` was omitted as nothing needed it. --- Source/Core/Common/StringUtil.h | 15 +++++++++++++++ Source/Core/Core/Config/DefaultLocale.cpp | 4 +--- Source/Core/Core/IOS/ES/NandUtils.cpp | 3 +-- Source/Core/Core/Movie.cpp | 2 +- Source/Core/DiscIO/DiscUtils.cpp | 4 ++-- .../Settings/USBDeviceAddToWhitelistDialog.cpp | 3 +-- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Source/Core/Common/StringUtil.h b/Source/Core/Common/StringUtil.h index 8aa5bd3f68..8ccc05ee6b 100644 --- a/Source/Core/Common/StringUtil.h +++ b/Source/Core/Common/StringUtil.h @@ -275,6 +275,21 @@ inline bool IsAlpha(char c) return std::isalpha(c, std::locale::classic()); } +inline bool IsAlnum(char c) +{ + return std::isalnum(c, std::locale::classic()); +} + +inline bool IsUpper(char c) +{ + return std::isupper(c, std::locale::classic()); +} + +inline bool IsXDigit(char c) +{ + return std::isxdigit(c /* no locale needed */) != 0; +} + inline char ToLower(char ch) { return std::tolower(ch, std::locale::classic()); diff --git a/Source/Core/Core/Config/DefaultLocale.cpp b/Source/Core/Core/Config/DefaultLocale.cpp index 82daf804cc..3610e42902 100644 --- a/Source/Core/Core/Config/DefaultLocale.cpp +++ b/Source/Core/Core/Config/DefaultLocale.cpp @@ -79,11 +79,9 @@ static DiscIO::Language ComputeDefaultLanguage() static std::optional TryParseCountryCode(const std::string& locale) { - const auto is_upper = [](char c) { return std::isupper(c, std::locale::classic()); }; - for (const std::string& part : SplitString(locale, '-')) { - if (part.size() == 2 && is_upper(part[0]) && is_upper(part[1])) + if (part.size() == 2 && Common::IsUpper(part[0]) && Common::IsUpper(part[1])) return part; } diff --git a/Source/Core/Core/IOS/ES/NandUtils.cpp b/Source/Core/Core/IOS/ES/NandUtils.cpp index 9c742974b8..b1ef7c8bd2 100644 --- a/Source/Core/Core/IOS/ES/NandUtils.cpp +++ b/Source/Core/Core/IOS/ES/NandUtils.cpp @@ -79,8 +79,7 @@ static bool IsValidPartOfTitleID(const std::string& string) { if (string.length() != 8) return false; - return std::all_of(string.begin(), string.end(), - [](const auto character) { return std::isxdigit(character) != 0; }); + return std::all_of(string.begin(), string.end(), Common::IsXDigit); } static std::vector GetTitlesInTitleOrImport(FS::FileSystem* fs, const std::string& titles_dir) diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 89e6d45d31..7c64b5f008 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -93,7 +93,7 @@ static std::array ConvertGitRevisionToBytes(const std::string& revision) { std::array revision_bytes{}; - if (revision.size() % 2 == 0 && std::all_of(revision.begin(), revision.end(), ::isxdigit)) + if (revision.size() % 2 == 0 && std::all_of(revision.begin(), revision.end(), Common::IsXDigit)) { // The revision string normally contains a git commit hash, // which is 40 hexadecimal digits long. In DTM files, each pair of diff --git a/Source/Core/DiscIO/DiscUtils.cpp b/Source/Core/DiscIO/DiscUtils.cpp index afd22117c6..5d03a5aa7f 100644 --- a/Source/Core/DiscIO/DiscUtils.cpp +++ b/Source/Core/DiscIO/DiscUtils.cpp @@ -13,6 +13,7 @@ #include "Common/CommonTypes.h" #include "Common/MathUtil.h" +#include "Common/StringUtil.h" #include "DiscIO/Blob.h" #include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" @@ -39,8 +40,7 @@ std::string NameForPartitionType(u32 partition_type, bool include_prefix) static_cast((partition_type >> 16) & 0xFF), static_cast((partition_type >> 8) & 0xFF), static_cast(partition_type & 0xFF)}; - if (std::all_of(type_as_game_id.cbegin(), type_as_game_id.cend(), - [](char c) { return std::isalnum(c, std::locale::classic()); })) + if (std::all_of(type_as_game_id.cbegin(), type_as_game_id.cend(), Common::IsAlnum)) { return include_prefix ? "P-" + type_as_game_id : type_as_game_id; } diff --git a/Source/Core/DolphinQt/Settings/USBDeviceAddToWhitelistDialog.cpp b/Source/Core/DolphinQt/Settings/USBDeviceAddToWhitelistDialog.cpp index d6add823d3..5ccb8b5bc9 100644 --- a/Source/Core/DolphinQt/Settings/USBDeviceAddToWhitelistDialog.cpp +++ b/Source/Core/DolphinQt/Settings/USBDeviceAddToWhitelistDialog.cpp @@ -30,8 +30,7 @@ static bool IsValidUSBIDString(const std::string& string) { if (string.empty() || string.length() > 4) return false; - return std::all_of(string.begin(), string.end(), - [](const auto character) { return std::isxdigit(character) != 0; }); + return std::all_of(string.begin(), string.end(), Common::IsXDigit); } USBDeviceAddToWhitelistDialog::USBDeviceAddToWhitelistDialog(QWidget* parent) : QDialog(parent)