]>
git.saurik.com Git - apple/javascriptcore.git/blob - wtf/unicode/brew/UnicodeBrew.cpp
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 * Copyright (C) 2010 Company 100, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #include "UnicodeBrew.h"
32 UChar
toLower(UChar c
)
37 UChar
toUpper(UChar c
)
42 UChar
foldCase(UChar c
)
47 bool isPrintableChar(UChar c
)
72 bool isAlphanumeric(UChar c
)
77 int toLower(UChar
* result
, int resultLength
, const UChar
* source
, int sourceLength
, bool* isError
)
79 const UChar
* sourceIterator
= source
;
80 const UChar
* sourceEnd
= source
+ sourceLength
;
81 UChar
* resultIterator
= result
;
82 UChar
* resultEnd
= result
+ resultLength
;
84 if (sourceLength
<= resultLength
) {
85 while (sourceIterator
< sourceEnd
)
86 *resultIterator
++ = towlower(*sourceIterator
++);
88 while (resultIterator
< resultEnd
)
89 *resultIterator
++ = towlower(*sourceIterator
++);
92 int remainingCharacters
= sourceIterator
< sourceEnd
? sourceEnd
- sourceIterator
: 0;
93 *isError
= !!remainingCharacters
;
94 if (resultIterator
< resultEnd
)
97 return (resultIterator
- result
) + remainingCharacters
;
100 int toUpper(UChar
* result
, int resultLength
, const UChar
* source
, int sourceLength
, bool* isError
)
102 const UChar
* sourceIterator
= source
;
103 const UChar
* sourceEnd
= source
+ sourceLength
;
104 UChar
* resultIterator
= result
;
105 UChar
* resultEnd
= result
+ resultLength
;
107 if (sourceLength
<= resultLength
) {
108 while (sourceIterator
< sourceEnd
)
109 *resultIterator
++ = towupper(*sourceIterator
++);
111 while (resultIterator
< resultEnd
)
112 *resultIterator
++ = towupper(*sourceIterator
++);
115 int remainingCharacters
= sourceIterator
< sourceEnd
? sourceEnd
- sourceIterator
: 0;
116 *isError
= !!remainingCharacters
;
117 if (resultIterator
< resultEnd
)
120 return (resultIterator
- result
) + remainingCharacters
;
123 int foldCase(UChar
* result
, int resultLength
, const UChar
* source
, int sourceLength
, bool* isError
)
126 if (resultLength
< sourceLength
) {
130 for (int i
= 0; i
< sourceLength
; ++i
)
131 result
[i
] = foldCase(source
[i
]);
135 UChar
toTitleCase(UChar c
)
140 Direction
direction(UChar32 c
)
142 return static_cast<Direction
>(ICU::direction(c
));
145 CharCategory
category(unsigned int c
)
147 return static_cast<CharCategory
>(TO_MASK((int8_t) ICU::category(c
)));
150 DecompositionType
decompositionType(UChar32 c
)
152 return static_cast<DecompositionType
>(ICU::decompositionType(c
));
155 unsigned char combiningClass(UChar32 c
)
157 return ICU::combiningClass(c
);
160 UChar
mirroredChar(UChar32 c
)
162 return ICU::mirroredChar(c
);
165 int digitValue(UChar c
)
167 return ICU::digitValue(c
);
170 bool isSpace(UChar c
)
172 return !!iswspace(c
);
175 bool isLetter(UChar c
)
177 return !!iswalpha(c
);
180 } // namespace Unicode