diff options
author | Jordan Rose <jordan_rose@apple.com> | 2013-02-08 22:30:41 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2013-02-08 22:30:41 +0000 |
commit | 3f6f51e28231f65de9c2dd150a2d757b2162cfa3 (patch) | |
tree | 1e341c81fec0bf620086a1afa40f4f847dc5bdc4 /include/clang/Basic/CharInfo.h | |
parent | 4a04d445af4d29440371800409babc98708d98aa (diff) |
Excise <cctype> from Clang (except clang-tblgen) in favor of CharInfo.h.
Nearly all of these changes are one-to-one replacements; the few that
aren't have to do with custom identifier validation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174768 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/CharInfo.h')
-rw-r--r-- | include/clang/Basic/CharInfo.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/include/clang/Basic/CharInfo.h b/include/clang/Basic/CharInfo.h index f9b7b7311d..2522face65 100644 --- a/include/clang/Basic/CharInfo.h +++ b/include/clang/Basic/CharInfo.h @@ -10,6 +10,8 @@ #ifndef CLANG_BASIC_CHARINFO_H #define CLANG_BASIC_CHARINFO_H +#include "clang/Basic/LLVM.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/DataTypes.h" @@ -157,6 +159,41 @@ LLVM_READONLY static inline bool isRawStringDelimBody(unsigned char c) { CHAR_DIGIT|CHAR_UNDER|CHAR_RAWDEL)) != 0; } + +/// Converts the given ASCII character to its lowercase equivalent. +/// +/// If the character is not an uppercase character, it is returned as is. +LLVM_READONLY static inline char toLowercase(char c) { + if (isUppercase(c)) + return c + 'a' - 'A'; + return c; +} + +/// Converts the given ASCII character to its uppercase equivalent. +/// +/// If the character is not a lowercase character, it is returned as is. +LLVM_READONLY static inline char toUppercase(char c) { + if (isLowercase(c)) + return c + 'A' - 'a'; + return c; +} + + +/// Return true if this is a valid ASCII identifier. +/// +/// Note that this is a very simple check; it does not accept '$' or UCNs as +/// valid identifier characters. +LLVM_READONLY static inline bool isValidIdentifier(StringRef S) { + if (S.empty() || !isIdentifierHead(S[0])) + return false; + + for (StringRef::iterator I = S.begin(), E = S.end(); I != E; ++I) + if (!isIdentifierBody(*I)) + return false; + + return true; +} + } // end namespace clang #endif |