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