StringUtil: Move IsAlpha() into Common namespace

This commit is contained in:
Lioncash 2023-05-16 14:11:02 -04:00
parent e0ef474d95
commit a9f1edeb61
2 changed files with 11 additions and 9 deletions

View File

@ -238,14 +238,6 @@ inline bool IsPrintableCharacter(char c)
return std::isprint(c, std::locale::classic()); return std::isprint(c, std::locale::classic());
} }
/// Returns whether a character is a letter, i.e. whether 'a' <= c <= 'z' || 'A' <= c <= 'Z'
/// is true. Use this instead of calling std::isalpha directly to ensure
/// the C locale is being used and to avoid possibly undefined behaviour.
inline bool IsAlpha(char c)
{
return std::isalpha(c, std::locale::classic());
}
#ifdef _WIN32 #ifdef _WIN32
std::vector<std::string> CommandLineToUtf8Argv(const wchar_t* command_line); std::vector<std::string> CommandLineToUtf8Argv(const wchar_t* command_line);
#endif #endif
@ -254,14 +246,24 @@ std::string GetEscapedHtml(std::string html);
namespace Common namespace Common
{ {
/// Returns whether a character is a letter, i.e. whether 'a' <= c <= 'z' || 'A' <= c <= 'Z'
/// is true. Use this instead of calling std::isalpha directly to ensure
/// the C locale is being used and to avoid possibly undefined behaviour.
inline bool IsAlpha(char c)
{
return std::isalpha(c, std::locale::classic());
}
inline char ToLower(char ch) inline char ToLower(char ch)
{ {
return std::tolower(ch, std::locale::classic()); return std::tolower(ch, std::locale::classic());
} }
inline char ToUpper(char ch) inline char ToUpper(char ch)
{ {
return std::toupper(ch, std::locale::classic()); return std::toupper(ch, std::locale::classic());
} }
void ToLower(std::string* str); void ToLower(std::string* str);
void ToUpper(std::string* str); void ToUpper(std::string* str);
bool CaseInsensitiveEquals(std::string_view a, std::string_view b); bool CaseInsensitiveEquals(std::string_view a, std::string_view b);

View File

@ -43,7 +43,7 @@ std::string GetExpressionForControl(const std::string& control_name,
{ {
// If our expression contains any non-alpha characters // If our expression contains any non-alpha characters
// we should quote it // we should quote it
if (!std::all_of(expr.begin(), expr.end(), IsAlpha)) if (!std::all_of(expr.begin(), expr.end(), Common::IsAlpha))
expr = fmt::format("`{}`", expr); expr = fmt::format("`{}`", expr);
} }