initial import
[vuplus_webkit] / Source / JavaScriptCore / wtf / unicode / wince / UnicodeWinCE.cpp
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"
23 #include "UnicodeWinCE.h"
24
25 #include <wchar.h>
26
27 namespace WTF {
28 namespace Unicode {
29
30 UChar toLower(UChar c)
31 {
32     return towlower(c);
33 }
34
35 UChar toUpper(UChar c)
36 {
37     return towupper(c);
38 }
39
40 UChar foldCase(UChar c)
41 {
42     return towlower(c);
43 }
44
45 bool isPrintableChar(UChar c)
46 {
47     return !!iswprint(c);
48 }
49
50 bool isSpace(UChar c)
51 {
52     return !!iswspace(c);
53 }
54
55 bool isLetter(UChar c)
56 {
57     return !!iswalpha(c);
58 }
59
60 bool isUpper(UChar c)
61 {
62     return !!iswupper(c);
63 }
64
65 bool isLower(UChar c)
66 {
67     return !!iswlower(c);
68 }
69
70 bool isDigit(UChar c)
71 {
72     return !!iswdigit(c);
73 }
74
75 bool isPunct(UChar c)
76 {
77     return !!iswpunct(c);
78 }
79
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)
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;
102     *isError = !!remainingCharacters;
103     if (resultIterator < resultEnd)
104         *resultIterator = 0;
105
106     return (resultIterator - result) + remainingCharacters;
107 }
108
109 int toUpper(UChar* result, int resultLength, const UChar* source, int sourceLength, bool* isError)
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;
126     *isError = !!remainingCharacters;
127     if (resultIterator < resultEnd)
128         *resultIterator = 0;
129
130     return (resultIterator - result) + remainingCharacters;
131 }
132
133 int foldCase(UChar* result, int resultLength, const UChar* source, int sourceLength, bool* isError)
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
145 UChar toTitleCase(UChar c)
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
170 UChar mirroredChar(UChar32 c)
171 {
172     return UnicodeCE::mirroredChar(c);
173 }
174
175 int digitValue(UChar c)
176 {
177     return UnicodeCE::digitValue(c);
178 }
179
180 } // namespace Unicode
181 } // namespace WTF