Changeset 24007 in vbox for trunk/include
- Timestamp:
- Oct 23, 2009 8:05:18 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/ctype.h
r8245 r24007 31 31 #define ___iprt_ctype_h 32 32 33 #include <iprt/types.h> 34 33 35 #ifdef IN_RING3 34 36 # include <ctype.h> … … 40 42 #endif /* IN_RING3 */ 41 43 42 /** @name C locale macros. 43 * 44 * @remarks The macros may reference the character more than once. 45 * @remarks Assumes a charset similar to ASCII. 46 * @remarks Can probably be optimized if someone has time. 44 /** @name C locale predicates and conversions. 45 * 46 * For most practical purposes, this can safely be used when parsing UTF-8 47 * strings. Just keep in mind that we only deal with the first 127 chars and 48 * that full correctness is only archived using the non-existing RTLocIs* API. 49 * 50 * @remarks Use the marcros, not the inlined functions. 51 * 52 * @remarks ASSUMES the source code includes the basic ASCII chars. This is a 53 * general IPRT assumption. 47 54 * @{ */ 48 #define RT_C_IS_BLANK(ch) ( (ch) == ' ' || (ch) == '\t' ) 49 #define RT_C_IS_ALNUM(ch) ( RT_C_IS_DIGIT(ch) || RT_C_IS_ALPHA(ch) ) 50 #define RT_C_IS_ALPHA(ch) ( RT_C_IS_LOWER(ch) || RT_C_IS_UPPER(ch) ) 51 #define RT_C_IS_CNTRL(ch) ( (ch) >= 0 && (ch) < 32 ) 52 #define RT_C_IS_DIGIT(ch) ( (ch) >= '0' && (ch) <= '9' ) 53 #define RT_C_IS_LOWER(ch) ( (ch) >= 'a' && (ch) <= 'z' ) 54 #define RT_C_IS_GRAPH(ch) ( RT_C_IS_PRINT(ch) && !RT_C_IS_BLANK(ch) ) 55 #define RT_C_IS_ODIGIT(ch) ( (ch) >= '0' && (ch) <= '7' ) 56 #define RT_C_IS_PRINT(ch) ( (ch) >= 32 && (ch) < 127 ) /**< @todo possibly incorrect */ 57 #define RT_C_IS_PUNCT(ch) ( (ch) == ',' || (ch) == '.' || (ch) == ':' || (ch) == ';' || (ch) == '!' || (ch) == '?' ) /**< @todo possibly incorrect */ 58 #define RT_C_IS_SPACE(ch) ( (ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r' || (ch) == '\f' || (ch) == '\v' ) 59 #define RT_C_IS_UPPER(ch) ( (ch) >= 'A' && (ch) <= 'Z' ) 60 #define RT_C_IS_XDIGIT(ch) ( RT_C_IS_DIGIT(ch) || ((ch) >= 'a' && (ch) <= 'f') || ((ch) >= 'A' && (ch) <= 'F') ) 61 62 #define RT_C_TO_LOWER(ch) ( RT_C_IS_UPPER(ch) ? (ch) + ('a' - 'A') : (ch) ) 63 #define RT_C_TO_UPPER(ch) ( RT_C_IS_LOWER(ch) ? (ch) - ('a' - 'A') : (ch) ) 55 #define RT_C_IS_BLANK(ch) RTLocCIsBlank((ch)) 56 #define RT_C_IS_ALNUM(ch) RTLocCIsAlNum((ch)) 57 #define RT_C_IS_ALPHA(ch) RTLocCIsAlpha((ch)) 58 #define RT_C_IS_CNTRL(ch) RTLocCIsCntrl((ch)) 59 #define RT_C_IS_DIGIT(ch) RTLocCIsDigit((ch)) 60 #define RT_C_IS_LOWER(ch) RTLocCIsLower((ch)) 61 #define RT_C_IS_GRAPH(ch) RTLocCIsGraph((ch)) 62 #define RT_C_IS_ODIGIT(ch) RTLocCIsODigit((ch)) 63 #define RT_C_IS_PRINT(ch) RTLocCIsPrint((ch)) 64 #define RT_C_IS_PUNCT(ch) RTLocCIsPunct((ch)) 65 #define RT_C_IS_SPACE(ch) RTLocCIsSpace((ch)) 66 #define RT_C_IS_UPPER(ch) RTLocCIsUpper((ch)) 67 #define RT_C_IS_XDIGIT(ch) RTLocCIsXDigit((ch)) 68 69 #define RT_C_TO_LOWER(ch) RTLocCToLower((ch)) 70 #define RT_C_TO_UPPER(ch) RTLocCToUpper((ch)) 71 72 /** 73 * Checks for a blank character. 74 * 75 * @returns true / false. 76 * @param ch The character to test. 77 */ 78 DECL_FORCE_INLINE(bool) RTLocCIsBlank(int ch) 79 { 80 return ch == ' ' || ch == '\t'; 81 } 82 83 /** 84 * Checks for a control character. 85 * 86 * @returns true / false. 87 * @param ch The character to test. 88 */ 89 DECL_FORCE_INLINE(bool) RTLocCIsCntrl(int ch) 90 { 91 return (ch) >= 0 && (ch) < 32; 92 } 93 94 /** 95 * Checks for a decimal digit. 96 * 97 * @returns true / false. 98 * @param ch The character to test. 99 */ 100 DECL_FORCE_INLINE(bool) RTLocCIsDigit(int ch) 101 { 102 return (ch) >= '0' && (ch) <= '9'; 103 } 104 105 /** 106 * Checks for a lower case character. 107 * 108 * @returns true / false. 109 * @param ch The character to test. 110 */ 111 DECL_FORCE_INLINE(bool) RTLocCIsLower(int ch) 112 { 113 return (ch) >= 'a' && (ch) <= 'z'; 114 } 115 116 /** 117 * Checks for a octal digit. 118 * 119 * @returns true / false. 120 * @param ch The character to test. 121 */ 122 DECL_FORCE_INLINE(bool) RTLocCIsODigit(int ch) 123 { 124 return (ch) >= '0' && (ch) <= '7'; 125 } 126 127 /** 128 * Checks for a printable character (whitespace included). 129 * 130 * @returns true / false. 131 * @param ch The character to test. 132 */ 133 DECL_FORCE_INLINE(bool) RTLocCIsPrint(int ch) 134 { 135 /** @todo quite possibly incorrect */ 136 return (ch) >= 32 && (ch) < 127; 137 } 138 139 /** 140 * Checks for punctuation (?). 141 * 142 * @returns true / false. 143 * @param ch The character to test. 144 */ 145 DECL_FORCE_INLINE(bool) RTLocCIsPunct(int ch) 146 { 147 /** @todo possibly incorrect */ 148 return (ch) == ',' || (ch) == '.' || (ch) == ':' || (ch) == ';' || (ch) == '!' || (ch) == '?'; 149 } 150 151 /** 152 * Checks for a white-space character. 153 * 154 * @returns true / false. 155 * @param ch The character to test. 156 */ 157 DECL_FORCE_INLINE(bool) RTLocCIsSpace(int ch) 158 { 159 return (ch) == ' ' || ((ch) >= '\t' && (ch) <= '\f'); 160 } 161 162 /** 163 * Checks for an upper case character. 164 * 165 * @returns true / false. 166 * @param ch The character to test. 167 */ 168 DECL_FORCE_INLINE(bool) RTLocCIsUpper(int ch) 169 { 170 return (ch) >= 'A' && (ch) <= 'Z'; 171 } 172 173 /** 174 * Checks for a hexadecimal digit. 175 * 176 * @returns true / false. 177 * @param ch The character to test. 178 */ 179 DECL_FORCE_INLINE(bool) RTLocCIsXDigit(int ch) 180 { 181 return RTLocCIsDigit(ch) || ((ch) >= 'a' && (ch) <= 'f') || ((ch) >= 'A' && (ch) <= 'F'); 182 } 183 184 /** 185 * Checks for an alphabetic character. 186 * 187 * @returns true / false. 188 * @param ch The character to test. 189 */ 190 DECL_FORCE_INLINE(bool) RTLocCIsAlpha(int ch) 191 { 192 return RTLocCIsLower(ch) || RTLocCIsUpper(ch); 193 } 194 195 /** 196 * Checks for an alphanumerical character. 197 * 198 * @returns true / false. 199 * @param ch The character to test. 200 */ 201 DECL_FORCE_INLINE(bool) RTLocCIsAlNum(int ch) 202 { 203 return RTLocCIsDigit(ch) || RTLocCIsAlpha(ch); 204 } 205 206 /** 207 * Checks for a printable character whitespace excluded. 208 * 209 * @returns true / false. 210 * @param ch The character to test. 211 */ 212 DECL_FORCE_INLINE(bool) RTLocCIsGraph(int ch) 213 { 214 return RTLocCIsPrint(ch) && !RTLocCIsBlank(ch); 215 } 216 217 218 /** 219 * Converts the character to lower case if applictable. 220 * 221 * @returns lower cased character or ch. 222 * @param ch The character to test. 223 */ 224 DECL_FORCE_INLINE(int) RTLocCToLower(int ch) 225 { 226 return RTLocCIsUpper(ch) ? (ch) + ('a' - 'A') : (ch); 227 } 228 229 /** 230 * Converts the character to upper case if applictable. 231 * 232 * @returns upper cased character or ch. 233 * @param ch The character to test. 234 */ 235 DECL_FORCE_INLINE(int) RTLocCToUpper(int ch) 236 { 237 return RTLocCIsLower(ch) ? (ch) - ('a' - 'A') : (ch); 238 } 239 240 64 241 /** @} */ 65 242
Note:
See TracChangeset
for help on using the changeset viewer.