mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-08 15:20:45 +01:00
StringUtil: More Wrappers For <cctype>
`Common::IsLower(char)` was omitted as nothing needed it.
This commit is contained in:
parent
b4a1967310
commit
826e2bbf98
@ -275,6 +275,21 @@ inline bool IsAlpha(char c)
|
|||||||
return std::isalpha(c, std::locale::classic());
|
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)
|
inline char ToLower(char ch)
|
||||||
{
|
{
|
||||||
return std::tolower(ch, std::locale::classic());
|
return std::tolower(ch, std::locale::classic());
|
||||||
|
@ -79,11 +79,9 @@ static DiscIO::Language ComputeDefaultLanguage()
|
|||||||
|
|
||||||
static std::optional<std::string> TryParseCountryCode(const std::string& locale)
|
static std::optional<std::string> 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, '-'))
|
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;
|
return part;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,8 +79,7 @@ static bool IsValidPartOfTitleID(const std::string& string)
|
|||||||
{
|
{
|
||||||
if (string.length() != 8)
|
if (string.length() != 8)
|
||||||
return false;
|
return false;
|
||||||
return std::all_of(string.begin(), string.end(),
|
return std::all_of(string.begin(), string.end(), Common::IsXDigit);
|
||||||
[](const auto character) { return std::isxdigit(character) != 0; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<u64> GetTitlesInTitleOrImport(FS::FileSystem* fs, const std::string& titles_dir)
|
static std::vector<u64> GetTitlesInTitleOrImport(FS::FileSystem* fs, const std::string& titles_dir)
|
||||||
|
@ -93,7 +93,7 @@ static std::array<u8, 20> ConvertGitRevisionToBytes(const std::string& revision)
|
|||||||
{
|
{
|
||||||
std::array<u8, 20> revision_bytes{};
|
std::array<u8, 20> 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,
|
// The revision string normally contains a git commit hash,
|
||||||
// which is 40 hexadecimal digits long. In DTM files, each pair of
|
// which is 40 hexadecimal digits long. In DTM files, each pair of
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/MathUtil.h"
|
#include "Common/MathUtil.h"
|
||||||
|
#include "Common/StringUtil.h"
|
||||||
#include "DiscIO/Blob.h"
|
#include "DiscIO/Blob.h"
|
||||||
#include "DiscIO/Filesystem.h"
|
#include "DiscIO/Filesystem.h"
|
||||||
#include "DiscIO/Volume.h"
|
#include "DiscIO/Volume.h"
|
||||||
@ -39,8 +40,7 @@ std::string NameForPartitionType(u32 partition_type, bool include_prefix)
|
|||||||
static_cast<char>((partition_type >> 16) & 0xFF),
|
static_cast<char>((partition_type >> 16) & 0xFF),
|
||||||
static_cast<char>((partition_type >> 8) & 0xFF),
|
static_cast<char>((partition_type >> 8) & 0xFF),
|
||||||
static_cast<char>(partition_type & 0xFF)};
|
static_cast<char>(partition_type & 0xFF)};
|
||||||
if (std::all_of(type_as_game_id.cbegin(), type_as_game_id.cend(),
|
if (std::all_of(type_as_game_id.cbegin(), type_as_game_id.cend(), Common::IsAlnum))
|
||||||
[](char c) { return std::isalnum(c, std::locale::classic()); }))
|
|
||||||
{
|
{
|
||||||
return include_prefix ? "P-" + type_as_game_id : type_as_game_id;
|
return include_prefix ? "P-" + type_as_game_id : type_as_game_id;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,7 @@ static bool IsValidUSBIDString(const std::string& string)
|
|||||||
{
|
{
|
||||||
if (string.empty() || string.length() > 4)
|
if (string.empty() || string.length() > 4)
|
||||||
return false;
|
return false;
|
||||||
return std::all_of(string.begin(), string.end(),
|
return std::all_of(string.begin(), string.end(), Common::IsXDigit);
|
||||||
[](const auto character) { return std::isxdigit(character) != 0; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
USBDeviceAddToWhitelistDialog::USBDeviceAddToWhitelistDialog(QWidget* parent) : QDialog(parent)
|
USBDeviceAddToWhitelistDialog::USBDeviceAddToWhitelistDialog(QWidget* parent) : QDialog(parent)
|
||||||
|
Loading…
Reference in New Issue
Block a user