WTF
ASCIICType.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef WTF_ASCIICType_h
00030 #define WTF_ASCIICType_h
00031
00032 #include <wtf/Platform.h>
00033 #include <wtf/Assertions.h>
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 namespace WTF {
00046
00047 inline bool isASCIIAlpha(char c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
00048 inline bool isASCIIAlpha(unsigned short c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
00049 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00050 inline bool isASCIIAlpha(wchar_t c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
00051 #endif
00052 inline bool isASCIIAlpha(int c) { return (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; }
00053
00054 inline bool isASCIIAlphanumeric(char c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
00055 inline bool isASCIIAlphanumeric(unsigned short c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
00056 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00057 inline bool isASCIIAlphanumeric(wchar_t c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
00058 #endif
00059 inline bool isASCIIAlphanumeric(int c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'z'); }
00060
00061 inline bool isASCIIDigit(char c) { return (c >= '0') & (c <= '9'); }
00062 inline bool isASCIIDigit(unsigned short c) { return (c >= '0') & (c <= '9'); }
00063 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00064 inline bool isASCIIDigit(wchar_t c) { return (c >= '0') & (c <= '9'); }
00065 #endif
00066 inline bool isASCIIDigit(int c) { return (c >= '0') & (c <= '9'); }
00067
00068 inline bool isASCIIHexDigit(char c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
00069 inline bool isASCIIHexDigit(unsigned short c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
00070 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00071 inline bool isASCIIHexDigit(wchar_t c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
00072 #endif
00073 inline bool isASCIIHexDigit(int c) { return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); }
00074
00075 inline bool isASCIILower(char c) { return c >= 'a' && c <= 'z'; }
00076 inline bool isASCIILower(unsigned short c) { return c >= 'a' && c <= 'z'; }
00077 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00078 inline bool isASCIILower(wchar_t c) { return c >= 'a' && c <= 'z'; }
00079 #endif
00080 inline bool isASCIILower(int c) { return c >= 'a' && c <= 'z'; }
00081
00082 inline bool isASCIIUpper(char c) { return c >= 'A' && c <= 'Z'; }
00083 inline bool isASCIIUpper(unsigned short c) { return c >= 'A' && c <= 'Z'; }
00084 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00085 inline bool isASCIIUpper(wchar_t c) { return c >= 'A' && c <= 'Z'; }
00086 #endif
00087 inline bool isASCIIUpper(int c) { return c >= 'A' && c <= 'Z'; }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 inline bool isASCIISpace(char c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
00103 inline bool isASCIISpace(unsigned short c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
00104 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00105 inline bool isASCIISpace(wchar_t c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
00106 #endif
00107 inline bool isASCIISpace(int c) { return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); }
00108
00109 inline char toASCIILower(char c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
00110 inline unsigned short toASCIILower(unsigned short c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
00111 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00112 inline wchar_t toASCIILower(wchar_t c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
00113 #endif
00114 inline int toASCIILower(int c) { return c | ((c >= 'A' && c <= 'Z') << 5); }
00115
00116 inline char toASCIIUpper(char c) { return static_cast<char>(c & ~((c >= 'a' && c <= 'z') << 5)); }
00117 inline unsigned short toASCIIUpper(unsigned short c) { return static_cast<unsigned short>(c & ~((c >= 'a' && c <= 'z') << 5)); }
00118 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00119 inline wchar_t toASCIIUpper(wchar_t c) { return static_cast<wchar_t>(c & ~((c >= 'a' && c <= 'z') << 5)); }
00120 #endif
00121 inline int toASCIIUpper(int c) { return static_cast<int>(c & ~((c >= 'a' && c <= 'z') << 5)); }
00122
00123 inline int toASCIIHexValue(char c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
00124 inline int toASCIIHexValue(unsigned short c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
00125 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
00126 inline int toASCIIHexValue(wchar_t c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
00127 #endif
00128 inline int toASCIIHexValue(int c) { ASSERT(isASCIIHexDigit(c)); return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; }
00129
00130 }
00131
00132 #endif