Index: llvm/include/llvm/ADT/StringExtras.h =================================================================== --- llvm/include/llvm/ADT/StringExtras.h +++ llvm/include/llvm/ADT/StringExtras.h @@ -98,10 +98,14 @@ /// Checks if character \p C is a hexadecimal numeric character. inline bool isHexDigit(char C) { return hexDigitValue(C) != ~0U; } +/// Checks if character \p C is a lowercase letter as classified by "C" locale. +inline bool isLower(char C) { return 'a' <= C && C <= 'z'; } + +/// Checks if character \p C is a uppercase letter as classified by "C" locale. +inline bool isUpper(char C) { return 'A' <= C && C <= 'Z'; } + /// Checks if character \p C is a valid letter as classified by "C" locale. -inline bool isAlpha(char C) { - return ('a' <= C && C <= 'z') || ('A' <= C && C <= 'Z'); -} +inline bool isAlpha(char C) { return isLower(C) || isUpper(C); } /// Checks whether character \p C is either a decimal digit or an uppercase or /// lowercase letter as classified by "C" locale. @@ -137,14 +141,14 @@ /// Returns the corresponding lowercase character if \p x is uppercase. inline char toLower(char x) { - if (x >= 'A' && x <= 'Z') + if (isUpper(x)) return x - 'A' + 'a'; return x; } /// Returns the corresponding uppercase character if \p x is lowercase. inline char toUpper(char x) { - if (x >= 'a' && x <= 'z') + if (isLower(x)) return x - 'a' + 'A'; return x; }