Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: runtime/third_party/jscre/ASCIICType.h

Issue 1071713003: - Remove JSCRE from the runtime. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 THIRD_PARTY_JSCRE_ASCIICTYPE_H_
30 #define THIRD_PARTY_JSCRE_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
35 // equivalents for some of the <ctype.h> functions are named more explicitly,
36 // not dependent on the C library locale, and we should also optimize them
37 // as needed.
38
39 // All functions return false or leave the character unchanged if passed
40 // a character that is outside the range 0-7F. So they can be used on
41 // Unicode strings or characters if the intent is to do processing only
42 // if the character is ASCII.
43
44 inline bool isASCIIAlpha(char c) {
45 return (c | 0x20) >= 'a' && (c | 0x20) <= 'z';
46 }
47 inline bool isASCIIAlpha(uint16_t c) {
48 return (c | 0x20) >= 'a' && (c | 0x20) <= 'z';
49 }
50 inline bool isASCIIAlpha(int c) {
51 return (c | 0x20) >= 'a' && (c | 0x20) <= 'z';
52 }
53
54 inline bool isASCIIAlphanumeric(char c) {
55 return (c >= '0' && c <= '9') ||
56 ((c | 0x20) >= 'a' && (c | 0x20) <= 'z');
57 }
58 inline bool isASCIIAlphanumeric(uint16_t c) {
59 return (c >= '0' && c <= '9') ||
60 ((c | 0x20) >= 'a' && (c | 0x20) <= 'z');
61 }
62 inline bool isASCIIAlphanumeric(int c) {
63 return (c >= '0' && c <= '9') ||
64 ((c | 0x20) >= 'a' && (c | 0x20) <= 'z');
65 }
66
67 inline bool isASCIIDigit(char c) { return (c >= '0') & (c <= '9'); }
68 inline bool isASCIIDigit(uint16_t c) {
69 return (c >= '0') & (c <= '9');
70 }
71 inline bool isASCIIDigit(int c) { return (c >= '0') & (c <= '9'); }
72
73 inline bool isASCIIHexDigit(char c) {
74 return (c >= '0' && c <= '9') ||
75 ((c | 0x20) >= 'a' && (c | 0x20) <= 'f');
76 }
77 inline bool isASCIIHexDigit(uint16_t c) {
78 return (c >= '0' && c <= '9') ||
79 ((c | 0x20) >= 'a' && (c | 0x20) <= 'f');
80 }
81 inline bool isASCIIHexDigit(int c) {
82 return (c >= '0' && c <= '9') ||
83 ((c | 0x20) >= 'a' && (c | 0x20) <= 'f');
84 }
85
86 inline bool isASCIILower(char c) { return c >= 'a' && c <= 'z'; }
87 inline bool isASCIILower(uint16_t c) { return c >= 'a' && c <= 'z'; }
88 inline bool isASCIILower(int c) { return c >= 'a' && c <= 'z'; }
89
90 inline bool isASCIIUpper(char c) { return c >= 'A' && c <= 'Z'; }
91 inline bool isASCIIUpper(uint16_t c) { return c >= 'A' && c <= 'Z'; }
92 inline bool isASCIIUpper(int c) { return c >= 'A' && c <= 'Z'; }
93
94 /*
95 Statistics from a run of Apple's page load test for callers of
96 isASCIISpace:
97
98 character count
99 --------- -----
100 non-spaces 689383
101 20 space 294720
102 0A \n 89059
103 09 \t 28320
104 0D \r 0
105 0C \f 0
106 0B \v 0
107 */
108 inline bool isASCIISpace(char c) {
109 return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
110 }
111 inline bool isASCIISpace(uint16_t c) {
112 return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
113 }
114 inline bool isASCIISpace(int c) {
115 return c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
116 }
117
118 inline char toASCIILower(char c) {
119 return c | ((c >= 'A' && c <= 'Z') << 5);
120 }
121 inline uint16_t toASCIILower(uint16_t c) {
122 return c | ((c >= 'A' && c <= 'Z') << 5);
123 }
124 inline int toASCIILower(int c) {
125 return c | ((c >= 'A' && c <= 'Z') << 5);
126 }
127
128 inline char toASCIIUpper(char c) {
129 return static_cast<char>(c & ~((c >= 'a' && c <= 'z') << 5));
130 }
131 inline uint16_t toASCIIUpper(uint16_t c) {
132 return static_cast<uint16_t>(c & ~((c >= 'a' && c <= 'z') << 5));
133 }
134 inline int toASCIIUpper(int c) {
135 return static_cast<int>(c & ~((c >= 'a' && c <= 'z') << 5));
136 }
137
138 inline int toASCIIHexValue(char c) {
139 ASSERT(isASCIIHexDigit(c));
140 return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF;
141 }
142 inline int toASCIIHexValue(uint16_t c) {
143 ASSERT(isASCIIHexDigit(c));
144 return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF;
145 }
146 inline int toASCIIHexValue(int c) {
147 ASSERT(isASCIIHexDigit(c));
148 return c < 'A' ? c - '0' : (c - 'A' + 10) & 0xF;
149 }
150
151 #endif // THIRD_PARTY_JSCRE_ASCIICTYPE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698