| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
| 14 * its contributors may be used to endorse or promote products derived | |
| 15 * from this software without specific prior written permission. | |
| 16 * | |
| 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 */ | |
| 28 | |
| 29 #ifndef WTF_ASCIICType_h | |
| 30 #define WTF_ASCIICType_h | |
| 31 | |
| 32 // The behavior of many of the functions in the <ctype.h> header is dependent | |
| 33 // on the current locale. But in the WebKit project, all uses of those functions | |
| 34 // are in code processing something that's not locale-specific. These equivalent
s | |
| 35 // for some of the <ctype.h> functions are named more explicitly, not dependent | |
| 36 // on the C library locale, and we should also optimize them as needed. | |
| 37 | |
| 38 // All functions return false or leave the character unchanged if passed a chara
cter | |
| 39 // that is outside the range 0-7F. So they can be used on Unicode strings or | |
| 40 // characters if the intent is to do processing only if the character is ASCII. | |
| 41 | |
| 42 inline bool isASCIIAlpha(char c) { return (c | 0x20) >= 'a' && (c | 0x20) <=
'z'; } | |
| 43 inline bool isASCIIAlpha(unsigned short c) { return (c | 0x20) >= 'a' && (c
| 0x20) <= 'z'; } | |
| 44 inline bool isASCIIAlpha(int c) { return (c | 0x20) >= 'a' && (c | 0x20) <=
'z'; } | |
| 45 | |
| 46 inline bool isASCIIAlphanumeric(char c) { return c >= '0' && c <= '9' || (c
| 0x20) >= 'a' && (c | 0x20) <= 'z'; } | |
| 47 inline bool isASCIIAlphanumeric(unsigned short c) { return c >= '0' && c <=
'9' || (c | 0x20) >= 'a' && (c | 0x20) <= 'z'; } | |
| 48 inline bool isASCIIAlphanumeric(int c) { return c >= '0' && c <= '9' || (c |
0x20) >= 'a' && (c | 0x20) <= 'z'; } | |
| 49 | |
| 50 inline bool isASCIIDigit(char c) { return (c >= '0') & (c <= '9'); } | |
| 51 inline bool isASCIIDigit(unsigned short c) { return (c >= '0') & (c <= '9');
} | |
| 52 inline bool isASCIIDigit(int c) { return (c >= '0') & (c <= '9'); } | |
| 53 | |
| 54 inline bool isASCIIHexDigit(char c) { return c >= '0' && c <= '9' || (c | 0x
20) >= 'a' && (c | 0x20) <= 'f'; } | |
| 55 inline bool isASCIIHexDigit(unsigned short c) { return c >= '0' && c <= '9'
|| (c | 0x20) >= 'a' && (c | 0x20) <= 'f'; } | |
| 56 inline bool isASCIIHexDigit(int c) { return c >= '0' && c <= '9' || (c | 0x2
0) >= 'a' && (c | 0x20) <= 'f'; } | |
| 57 | |
| 58 inline bool isASCIILower(char c) { return c >= 'a' && c <= 'z'; } | |
| 59 inline bool isASCIILower(unsigned short c) { return c >= 'a' && c <= 'z'; } | |
| 60 inline bool isASCIILower(int c) { return c >= 'a' && c <= 'z'; } | |
| 61 | |
| 62 inline bool isASCIIUpper(char c) { return c >= 'A' && c <= 'Z'; } | |
| 63 inline bool isASCIIUpper(unsigned short c) { return c >= 'A' && c <= 'Z'; } | |
| 64 inline bool isASCIIUpper(int c) { return c >= 'A' && c <= 'Z'; } | |
| 65 | |
| 66 /* | |
| 67 Statistics from a run of Apple's page load test for callers of isASCIISp
ace: | |
| 68 | |
| 69 character count | |
| 70 --------- ----- | |
| 71 non-spaces 689383 | |
| 72 20 space 294720 | |
| 73 0A \n 89059 | |
| 74 09 \t 28320 | |
| 75 0D \r 0 | |
| 76 0C \f 0 | |
| 77 0B \v 0 | |
| 78 */ | |
| 79 inline bool isASCIISpace(char c) { return c <= ' ' && (c == ' ' || (c <= 0xD
&& c >= 0x9)); } | |
| 80 inline bool isASCIISpace(unsigned short c) { return c <= ' ' && (c == ' ' ||
(c <= 0xD && c >= 0x9)); } | |
| 81 inline bool isASCIISpace(int c) { return c <= ' ' && (c == ' ' || (c <= 0xD
&& c >= 0x9)); } | |
| 82 | |
| 83 inline char toASCIILower(char c) { return c | ((c >= 'A' && c <= 'Z') << 5);
} | |
| 84 inline unsigned short toASCIILower(unsigned short c) { return c | ((c >= 'A'
&& c <= 'Z') << 5); } | |
| 85 inline int toASCIILower(int c) { return c | ((c >= 'A' && c <= 'Z') << 5); } | |
| 86 | |
| 87 inline char toASCIIUpper(char c) { return static_cast<char>(c & ~((c >= 'a'
&& c <= 'z') << 5)); } | |
| 88 inline unsigned short toASCIIUpper(unsigned short c) { return static_cast<un
signed short>(c & ~((c >= 'a' && c <= 'z') << 5)); } | |
| 89 inline int toASCIIUpper(int c) { return static_cast<int>(c & ~((c >= 'a' &&
c <= 'z') << 5)); } | |
| 90 | |
| 91 inline int toASCIIHexValue(char c) { ASSERT(isASCIIHexDigit(c)); return c <
'A' ? c - '0' : (c - 'A' + 10) & 0xF; } | |
| 92 inline int toASCIIHexValue(unsigned short c) { ASSERT(isASCIIHexDigit(c)); r
eturn c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF; } | |
| 93 inline int toASCIIHexValue(int c) { ASSERT(isASCIIHexDigit(c)); return c < '
A' ? c - '0' : (c - 'A' + 10) & 0xF; } | |
| 94 | |
| 95 #endif | |
| OLD | NEW |