| 1 | /* |
| 2 | * Copyright (C) 2006 George Staikos <[email protected]> |
| 3 | * Copyright (C) 2006 Alexey Proskuryakov <[email protected]> |
| 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 | wchar_t toLower(wchar_t c) |
| 31 | { |
| 32 | return towlower(c); |
| 33 | } |
| 34 | |
| 35 | wchar_t toUpper(wchar_t c) |
| 36 | { |
| 37 | return towupper(c); |
| 38 | } |
| 39 | |
| 40 | wchar_t foldCase(wchar_t c) |
| 41 | { |
| 42 | return towlower(c); |
| 43 | } |
| 44 | |
| 45 | bool isPrintableChar(wchar_t c) |
| 46 | { |
| 47 | return !!iswprint(c); |
| 48 | } |
| 49 | |
| 50 | bool isSpace(wchar_t c) |
| 51 | { |
| 52 | return !!iswspace(c); |
| 53 | } |
| 54 | |
| 55 | bool isLetter(wchar_t c) |
| 56 | { |
| 57 | return !!iswalpha(c); |
| 58 | } |
| 59 | |
| 60 | bool isUpper(wchar_t c) |
| 61 | { |
| 62 | return !!iswupper(c); |
| 63 | } |
| 64 | |
| 65 | bool isLower(wchar_t c) |
| 66 | { |
| 67 | return !!iswlower(c); |
| 68 | } |
| 69 | |
| 70 | bool isDigit(wchar_t c) |
| 71 | { |
| 72 | return !!iswdigit(c); |
| 73 | } |
| 74 | |
| 75 | bool isPunct(wchar_t c) |
| 76 | { |
| 77 | return !!iswpunct(c); |
| 78 | } |
| 79 | |
| 80 | int toLower(wchar_t* result, int resultLength, const wchar_t* source, int sourceLength, bool* isError) |
| 81 | { |
| 82 | const UChar* sourceIterator = source; |
| 83 | const UChar* sourceEnd = source + sourceLength; |
| 84 | UChar* resultIterator = result; |
| 85 | UChar* resultEnd = result + resultLength; |
| 86 | |
| 87 | int remainingCharacters = 0; |
| 88 | if (sourceLength <= resultLength) |
| 89 | while (sourceIterator < sourceEnd) |
| 90 | *resultIterator++ = towlower(*sourceIterator++); |
| 91 | else |
| 92 | while (resultIterator < resultEnd) |
| 93 | *resultIterator++ = towlower(*sourceIterator++); |
| 94 | |
| 95 | if (sourceIterator < sourceEnd) |
| 96 | remainingCharacters += sourceEnd - sourceIterator; |
| 97 | *isError = (remainingCharacters != 0); |
| 98 | if (resultIterator < resultEnd) |
| 99 | *resultIterator = 0; |
| 100 | |
| 101 | return (resultIterator - result) + remainingCharacters; |
| 102 | } |
| 103 | |
| 104 | int toUpper(wchar_t* result, int resultLength, const wchar_t* source, int sourceLength, bool* isError) |
| 105 | { |
| 106 | const UChar* sourceIterator = source; |
| 107 | const UChar* sourceEnd = source + sourceLength; |
| 108 | UChar* resultIterator = result; |
| 109 | UChar* resultEnd = result + resultLength; |
| 110 | |
| 111 | int remainingCharacters = 0; |
| 112 | if (sourceLength <= resultLength) |
| 113 | while (sourceIterator < sourceEnd) |
| 114 | *resultIterator++ = towupper(*sourceIterator++); |
| 115 | else |
| 116 | while (resultIterator < resultEnd) |
| 117 | *resultIterator++ = towupper(*sourceIterator++); |
| 118 | |
| 119 | if (sourceIterator < sourceEnd) |
| 120 | remainingCharacters += sourceEnd - sourceIterator; |
| 121 | *isError = (remainingCharacters != 0); |
| 122 | if (resultIterator < resultEnd) |
| 123 | *resultIterator = 0; |
| 124 | |
| 125 | return (resultIterator - result) + remainingCharacters; |
| 126 | } |
| 127 | |
| 128 | int foldCase(wchar_t* result, int resultLength, const wchar_t* source, int sourceLength, bool* isError) |
| 129 | { |
| 130 | *isError = false; |
| 131 | if (resultLength < sourceLength) { |
| 132 | *isError = true; |
| 133 | return sourceLength; |
| 134 | } |
| 135 | for (int i = 0; i < sourceLength; ++i) |
| 136 | result[i] = foldCase(source[i]); |
| 137 | return sourceLength; |
| 138 | } |
| 139 | |
| 140 | wchar_t toTitleCase(wchar_t c) |
| 141 | { |
| 142 | return towupper(c); |
| 143 | } |
| 144 | |
| 145 | Direction direction(UChar32 c) |
| 146 | { |
| 147 | return static_cast<Direction>(UnicodeCE::direction(c)); |
| 148 | } |
| 149 | |
| 150 | CharCategory category(unsigned int c) |
| 151 | { |
| 152 | return static_cast<CharCategory>(TO_MASK((__int8) UnicodeCE::category(c))); |
| 153 | } |
| 154 | |
| 155 | DecompositionType decompositionType(UChar32 c) |
| 156 | { |
| 157 | return static_cast<DecompositionType>(UnicodeCE::decompositionType(c)); |
| 158 | } |
| 159 | |
| 160 | unsigned char combiningClass(UChar32 c) |
| 161 | { |
| 162 | return UnicodeCE::combiningClass(c); |
| 163 | } |
| 164 | |
| 165 | wchar_t mirroredChar(UChar32 c) |
| 166 | { |
| 167 | return UnicodeCE::mirroredChar(c); |
| 168 | } |
| 169 | |
| 170 | int digitValue(wchar_t c) |
| 171 | { |
| 172 | return UnicodeCE::digitValue(c); |
| 173 | } |
| 174 | |
| 175 | } // namespace Unicode |
| 176 | } // namespace WTF |