/// lowercase letter as classified by "C" locale.
inline bool isAlnum(char C) { return isAlpha(C) || isDigit(C); }
+/// Returns the corresponding lowercase character if \p x is uppercase.
+inline char toLower(char x) {
+ if (x >= 'A' && x <= 'Z')
+ 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')
+ return x - 'a' + 'A';
+ return x;
+}
+
inline std::string utohexstr(uint64_t X, bool LowerCase = false) {
char Buffer[17];
char *BufPtr = std::end(Buffer);
/// it if it is not printable or if it is an escape char.
void PrintEscapedString(StringRef Name, raw_ostream &Out);
+/// printLowerCase - Print each character as lowercase if it is uppercase.
+void printLowerCase(StringRef String, raw_ostream &Out);
+
namespace detail {
template <typename IteratorT>
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/edit_distance.h"
#include <bitset>
const size_t StringRef::npos;
#endif
-static char ascii_tolower(char x) {
- if (x >= 'A' && x <= 'Z')
- return x - 'A' + 'a';
- return x;
-}
-
-static char ascii_toupper(char x) {
- if (x >= 'a' && x <= 'z')
- return x - 'a' + 'A';
- return x;
-}
-
-static bool ascii_isdigit(char x) {
- return x >= '0' && x <= '9';
-}
-
// strncasecmp() is not available on non-POSIX systems, so define an
// alternative function here.
static int ascii_strncasecmp(const char *LHS, const char *RHS, size_t Length) {
for (size_t I = 0; I < Length; ++I) {
- unsigned char LHC = ascii_tolower(LHS[I]);
- unsigned char RHC = ascii_tolower(RHS[I]);
+ unsigned char LHC = toLower(LHS[I]);
+ unsigned char RHC = toLower(RHS[I]);
if (LHC != RHC)
return LHC < RHC ? -1 : 1;
}
}
size_t StringRef::find_lower(char C, size_t From) const {
- char L = ascii_tolower(C);
- return find_if([L](char D) { return ascii_tolower(D) == L; }, From);
+ char L = toLower(C);
+ return find_if([L](char D) { return toLower(D) == L; }, From);
}
/// compare_numeric - Compare strings, handle embedded numbers.
int StringRef::compare_numeric(StringRef RHS) const {
for (size_t I = 0, E = std::min(Length, RHS.Length); I != E; ++I) {
// Check for sequences of digits.
- if (ascii_isdigit(Data[I]) && ascii_isdigit(RHS.Data[I])) {
+ if (isDigit(Data[I]) && isDigit(RHS.Data[I])) {
// The longer sequence of numbers is considered larger.
// This doesn't really handle prefixed zeros well.
size_t J;
for (J = I + 1; J != E + 1; ++J) {
- bool ld = J < Length && ascii_isdigit(Data[J]);
- bool rd = J < RHS.Length && ascii_isdigit(RHS.Data[J]);
+ bool ld = J < Length && isDigit(Data[J]);
+ bool rd = J < RHS.Length && isDigit(RHS.Data[J]);
if (ld != rd)
return rd ? -1 : 1;
if (!rd)
std::string StringRef::lower() const {
std::string Result(size(), char());
for (size_type i = 0, e = size(); i != e; ++i) {
- Result[i] = ascii_tolower(Data[i]);
+ Result[i] = toLower(Data[i]);
}
return Result;
}
std::string StringRef::upper() const {
std::string Result(size(), char());
for (size_type i = 0, e = size(); i != e; ++i) {
- Result[i] = ascii_toupper(Data[i]);
+ Result[i] = toUpper(Data[i]);
}
return Result;
}
size_t i = From;
while (i != 0) {
--i;
- if (ascii_tolower(Data[i]) == ascii_tolower(C))
+ if (toLower(Data[i]) == toLower(C))
return i;
}
return npos;
return 8;
}
- if (Str[0] == '0' && Str.size() > 1 && ascii_isdigit(Str[1])) {
+ if (Str[0] == '0' && Str.size() > 1 && isDigit(Str[1])) {
Str = Str.substr(1);
return 8;
}