]>
Commit | Line | Data |
---|---|---|
f9bf01c6 A |
1 | /* |
2 | * Copyright (C) 2006 George Staikos <staikos@kde.org> | |
3 | * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> | |
4 | * Copyright (C) 2007-2009 Torch Mobile, Inc. | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Library General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Library General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Library General Public License | |
17 | * along with this library; see the file COPYING.LIB. If not, write to | |
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
19 | * Boston, MA 02110-1301, USA. | |
20 | */ | |
21 | ||
22 | #include "config.h" | |
14957cd0 | 23 | #include "UnicodeWinCE.h" |
f9bf01c6 A |
24 | |
25 | #include <wchar.h> | |
26 | ||
27 | namespace WTF { | |
28 | namespace Unicode { | |
29 | ||
14957cd0 | 30 | UChar toLower(UChar c) |
f9bf01c6 A |
31 | { |
32 | return towlower(c); | |
33 | } | |
34 | ||
14957cd0 | 35 | UChar toUpper(UChar c) |
f9bf01c6 A |
36 | { |
37 | return towupper(c); | |
38 | } | |
39 | ||
14957cd0 | 40 | UChar foldCase(UChar c) |
f9bf01c6 A |
41 | { |
42 | return towlower(c); | |
43 | } | |
44 | ||
14957cd0 | 45 | bool isPrintableChar(UChar c) |
f9bf01c6 A |
46 | { |
47 | return !!iswprint(c); | |
48 | } | |
49 | ||
14957cd0 | 50 | bool isSpace(UChar c) |
f9bf01c6 A |
51 | { |
52 | return !!iswspace(c); | |
53 | } | |
54 | ||
14957cd0 | 55 | bool isLetter(UChar c) |
f9bf01c6 A |
56 | { |
57 | return !!iswalpha(c); | |
58 | } | |
59 | ||
14957cd0 | 60 | bool isUpper(UChar c) |
f9bf01c6 A |
61 | { |
62 | return !!iswupper(c); | |
63 | } | |
64 | ||
14957cd0 | 65 | bool isLower(UChar c) |
f9bf01c6 A |
66 | { |
67 | return !!iswlower(c); | |
68 | } | |
69 | ||
14957cd0 | 70 | bool isDigit(UChar c) |
f9bf01c6 A |
71 | { |
72 | return !!iswdigit(c); | |
73 | } | |
74 | ||
14957cd0 | 75 | bool isPunct(UChar c) |
f9bf01c6 A |
76 | { |
77 | return !!iswpunct(c); | |
78 | } | |
79 | ||
14957cd0 A |
80 | bool isAlphanumeric(UChar c) |
81 | { | |
82 | return !!iswalnum(c); | |
83 | } | |
84 | ||
85 | int toLower(UChar* result, int resultLength, const UChar* source, int sourceLength, bool* isError) | |
f9bf01c6 A |
86 | { |
87 | const UChar* sourceIterator = source; | |
88 | const UChar* sourceEnd = source + sourceLength; | |
89 | UChar* resultIterator = result; | |
90 | UChar* resultEnd = result + resultLength; | |
91 | ||
92 | int remainingCharacters = 0; | |
93 | if (sourceLength <= resultLength) | |
94 | while (sourceIterator < sourceEnd) | |
95 | *resultIterator++ = towlower(*sourceIterator++); | |
96 | else | |
97 | while (resultIterator < resultEnd) | |
98 | *resultIterator++ = towlower(*sourceIterator++); | |
99 | ||
100 | if (sourceIterator < sourceEnd) | |
101 | remainingCharacters += sourceEnd - sourceIterator; | |
14957cd0 | 102 | *isError = !!remainingCharacters; |
f9bf01c6 A |
103 | if (resultIterator < resultEnd) |
104 | *resultIterator = 0; | |
105 | ||
106 | return (resultIterator - result) + remainingCharacters; | |
107 | } | |
108 | ||
14957cd0 | 109 | int toUpper(UChar* result, int resultLength, const UChar* source, int sourceLength, bool* isError) |
f9bf01c6 A |
110 | { |
111 | const UChar* sourceIterator = source; | |
112 | const UChar* sourceEnd = source + sourceLength; | |
113 | UChar* resultIterator = result; | |
114 | UChar* resultEnd = result + resultLength; | |
115 | ||
116 | int remainingCharacters = 0; | |
117 | if (sourceLength <= resultLength) | |
118 | while (sourceIterator < sourceEnd) | |
119 | *resultIterator++ = towupper(*sourceIterator++); | |
120 | else | |
121 | while (resultIterator < resultEnd) | |
122 | *resultIterator++ = towupper(*sourceIterator++); | |
123 | ||
124 | if (sourceIterator < sourceEnd) | |
125 | remainingCharacters += sourceEnd - sourceIterator; | |
14957cd0 | 126 | *isError = !!remainingCharacters; |
f9bf01c6 A |
127 | if (resultIterator < resultEnd) |
128 | *resultIterator = 0; | |
129 | ||
130 | return (resultIterator - result) + remainingCharacters; | |
131 | } | |
132 | ||
14957cd0 | 133 | int foldCase(UChar* result, int resultLength, const UChar* source, int sourceLength, bool* isError) |
f9bf01c6 A |
134 | { |
135 | *isError = false; | |
136 | if (resultLength < sourceLength) { | |
137 | *isError = true; | |
138 | return sourceLength; | |
139 | } | |
140 | for (int i = 0; i < sourceLength; ++i) | |
141 | result[i] = foldCase(source[i]); | |
142 | return sourceLength; | |
143 | } | |
144 | ||
14957cd0 | 145 | UChar toTitleCase(UChar c) |
f9bf01c6 A |
146 | { |
147 | return towupper(c); | |
148 | } | |
149 | ||
150 | Direction direction(UChar32 c) | |
151 | { | |
152 | return static_cast<Direction>(UnicodeCE::direction(c)); | |
153 | } | |
154 | ||
155 | CharCategory category(unsigned int c) | |
156 | { | |
157 | return static_cast<CharCategory>(TO_MASK((__int8) UnicodeCE::category(c))); | |
158 | } | |
159 | ||
160 | DecompositionType decompositionType(UChar32 c) | |
161 | { | |
162 | return static_cast<DecompositionType>(UnicodeCE::decompositionType(c)); | |
163 | } | |
164 | ||
165 | unsigned char combiningClass(UChar32 c) | |
166 | { | |
167 | return UnicodeCE::combiningClass(c); | |
168 | } | |
169 | ||
14957cd0 | 170 | UChar mirroredChar(UChar32 c) |
f9bf01c6 A |
171 | { |
172 | return UnicodeCE::mirroredChar(c); | |
173 | } | |
174 | ||
14957cd0 | 175 | int digitValue(UChar c) |
f9bf01c6 A |
176 | { |
177 | return UnicodeCE::digitValue(c); | |
178 | } | |
179 | ||
180 | } // namespace Unicode | |
181 | } // namespace WTF |