| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 George Staikos <staikos@kde.org> | 2 * Copyright (C) 2006 George Staikos <staikos@kde.org> |
| 3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> | 3 * Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com> |
| 4 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 4 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #define WTF_UnicodeIcu_h | 24 #define WTF_UnicodeIcu_h |
| 25 | 25 |
| 26 #include <unicode/uchar.h> | 26 #include <unicode/uchar.h> |
| 27 #include <unicode/ustring.h> | 27 #include <unicode/ustring.h> |
| 28 | 28 |
| 29 namespace WTF { | 29 namespace WTF { |
| 30 | 30 |
| 31 namespace Unicode { | 31 namespace Unicode { |
| 32 | 32 |
| 33 enum Direction { | 33 enum Direction { |
| 34 LeftToRight = U_LEFT_TO_RIGHT, | 34 LeftToRight = U_LEFT_TO_RIGHT, |
| 35 RightToLeft = U_RIGHT_TO_LEFT, | 35 RightToLeft = U_RIGHT_TO_LEFT, |
| 36 EuropeanNumber = U_EUROPEAN_NUMBER, | 36 EuropeanNumber = U_EUROPEAN_NUMBER, |
| 37 EuropeanNumberSeparator = U_EUROPEAN_NUMBER_SEPARATOR, | 37 EuropeanNumberSeparator = U_EUROPEAN_NUMBER_SEPARATOR, |
| 38 EuropeanNumberTerminator = U_EUROPEAN_NUMBER_TERMINATOR, | 38 EuropeanNumberTerminator = U_EUROPEAN_NUMBER_TERMINATOR, |
| 39 ArabicNumber = U_ARABIC_NUMBER, | 39 ArabicNumber = U_ARABIC_NUMBER, |
| 40 CommonNumberSeparator = U_COMMON_NUMBER_SEPARATOR, | 40 CommonNumberSeparator = U_COMMON_NUMBER_SEPARATOR, |
| 41 BlockSeparator = U_BLOCK_SEPARATOR, | 41 BlockSeparator = U_BLOCK_SEPARATOR, |
| 42 SegmentSeparator = U_SEGMENT_SEPARATOR, | 42 SegmentSeparator = U_SEGMENT_SEPARATOR, |
| 43 WhiteSpaceNeutral = U_WHITE_SPACE_NEUTRAL, | 43 WhiteSpaceNeutral = U_WHITE_SPACE_NEUTRAL, |
| 44 OtherNeutral = U_OTHER_NEUTRAL, | 44 OtherNeutral = U_OTHER_NEUTRAL, |
| 45 LeftToRightEmbedding = U_LEFT_TO_RIGHT_EMBEDDING, | 45 LeftToRightEmbedding = U_LEFT_TO_RIGHT_EMBEDDING, |
| 46 LeftToRightOverride = U_LEFT_TO_RIGHT_OVERRIDE, | 46 LeftToRightOverride = U_LEFT_TO_RIGHT_OVERRIDE, |
| 47 RightToLeftArabic = U_RIGHT_TO_LEFT_ARABIC, | 47 RightToLeftArabic = U_RIGHT_TO_LEFT_ARABIC, |
| 48 RightToLeftEmbedding = U_RIGHT_TO_LEFT_EMBEDDING, | 48 RightToLeftEmbedding = U_RIGHT_TO_LEFT_EMBEDDING, |
| 49 RightToLeftOverride = U_RIGHT_TO_LEFT_OVERRIDE, | 49 RightToLeftOverride = U_RIGHT_TO_LEFT_OVERRIDE, |
| 50 PopDirectionalFormat = U_POP_DIRECTIONAL_FORMAT, | 50 PopDirectionalFormat = U_POP_DIRECTIONAL_FORMAT, |
| 51 NonSpacingMark = U_DIR_NON_SPACING_MARK, | 51 NonSpacingMark = U_DIR_NON_SPACING_MARK, |
| 52 BoundaryNeutral = U_BOUNDARY_NEUTRAL | 52 BoundaryNeutral = U_BOUNDARY_NEUTRAL |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 enum DecompositionType { | 55 enum DecompositionType { |
| 56 DecompositionNone = U_DT_NONE, | 56 DecompositionNone = U_DT_NONE, |
| 57 DecompositionCanonical = U_DT_CANONICAL, | 57 DecompositionCanonical = U_DT_CANONICAL, |
| 58 DecompositionCompat = U_DT_COMPAT, | 58 DecompositionCompat = U_DT_COMPAT, |
| 59 DecompositionCircle = U_DT_CIRCLE, | 59 DecompositionCircle = U_DT_CIRCLE, |
| 60 DecompositionFinal = U_DT_FINAL, | 60 DecompositionFinal = U_DT_FINAL, |
| 61 DecompositionFont = U_DT_FONT, | 61 DecompositionFont = U_DT_FONT, |
| 62 DecompositionFraction = U_DT_FRACTION, | 62 DecompositionFraction = U_DT_FRACTION, |
| 63 DecompositionInitial = U_DT_INITIAL, | 63 DecompositionInitial = U_DT_INITIAL, |
| 64 DecompositionIsolated = U_DT_ISOLATED, | 64 DecompositionIsolated = U_DT_ISOLATED, |
| 65 DecompositionMedial = U_DT_MEDIAL, | 65 DecompositionMedial = U_DT_MEDIAL, |
| 66 DecompositionNarrow = U_DT_NARROW, | 66 DecompositionNarrow = U_DT_NARROW, |
| 67 DecompositionNoBreak = U_DT_NOBREAK, | 67 DecompositionNoBreak = U_DT_NOBREAK, |
| 68 DecompositionSmall = U_DT_SMALL, | 68 DecompositionSmall = U_DT_SMALL, |
| 69 DecompositionSquare = U_DT_SQUARE, | 69 DecompositionSquare = U_DT_SQUARE, |
| 70 DecompositionSub = U_DT_SUB, | 70 DecompositionSub = U_DT_SUB, |
| 71 DecompositionSuper = U_DT_SUPER, | 71 DecompositionSuper = U_DT_SUPER, |
| 72 DecompositionVertical = U_DT_VERTICAL, | 72 DecompositionVertical = U_DT_VERTICAL, |
| 73 DecompositionWide = U_DT_WIDE, | 73 DecompositionWide = U_DT_WIDE, |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 enum CharCategory { | 76 enum CharCategory { |
| 77 NoCategory = 0, | 77 NoCategory = 0, |
| 78 Other_NotAssigned = U_MASK(U_GENERAL_OTHER_TYPES), | 78 Other_NotAssigned = U_MASK(U_GENERAL_OTHER_TYPES), |
| 79 Letter_Uppercase = U_MASK(U_UPPERCASE_LETTER), | 79 Letter_Uppercase = U_MASK(U_UPPERCASE_LETTER), |
| 80 Letter_Lowercase = U_MASK(U_LOWERCASE_LETTER), | 80 Letter_Lowercase = U_MASK(U_LOWERCASE_LETTER), |
| 81 Letter_Titlecase = U_MASK(U_TITLECASE_LETTER), | 81 Letter_Titlecase = U_MASK(U_TITLECASE_LETTER), |
| 82 Letter_Modifier = U_MASK(U_MODIFIER_LETTER), | 82 Letter_Modifier = U_MASK(U_MODIFIER_LETTER), |
| 83 Letter_Other = U_MASK(U_OTHER_LETTER), | 83 Letter_Other = U_MASK(U_OTHER_LETTER), |
| 84 | 84 |
| 85 Mark_NonSpacing = U_MASK(U_NON_SPACING_MARK), | 85 Mark_NonSpacing = U_MASK(U_NON_SPACING_MARK), |
| 86 Mark_Enclosing = U_MASK(U_ENCLOSING_MARK), | 86 Mark_Enclosing = U_MASK(U_ENCLOSING_MARK), |
| 87 Mark_SpacingCombining = U_MASK(U_COMBINING_SPACING_MARK), | 87 Mark_SpacingCombining = U_MASK(U_COMBINING_SPACING_MARK), |
| 88 | 88 |
| 89 Number_DecimalDigit = U_MASK(U_DECIMAL_DIGIT_NUMBER), | 89 Number_DecimalDigit = U_MASK(U_DECIMAL_DIGIT_NUMBER), |
| 90 Number_Letter = U_MASK(U_LETTER_NUMBER), | 90 Number_Letter = U_MASK(U_LETTER_NUMBER), |
| 91 Number_Other = U_MASK(U_OTHER_NUMBER), | 91 Number_Other = U_MASK(U_OTHER_NUMBER), |
| 92 | 92 |
| 93 Separator_Space = U_MASK(U_SPACE_SEPARATOR), | 93 Separator_Space = U_MASK(U_SPACE_SEPARATOR), |
| 94 Separator_Line = U_MASK(U_LINE_SEPARATOR), | 94 Separator_Line = U_MASK(U_LINE_SEPARATOR), |
| 95 Separator_Paragraph = U_MASK(U_PARAGRAPH_SEPARATOR), | 95 Separator_Paragraph = U_MASK(U_PARAGRAPH_SEPARATOR), |
| 96 | 96 |
| 97 Other_Control = U_MASK(U_CONTROL_CHAR), | 97 Other_Control = U_MASK(U_CONTROL_CHAR), |
| 98 Other_Format = U_MASK(U_FORMAT_CHAR), | 98 Other_Format = U_MASK(U_FORMAT_CHAR), |
| 99 Other_PrivateUse = U_MASK(U_PRIVATE_USE_CHAR), | 99 Other_PrivateUse = U_MASK(U_PRIVATE_USE_CHAR), |
| 100 Other_Surrogate = U_MASK(U_SURROGATE), | 100 Other_Surrogate = U_MASK(U_SURROGATE), |
| 101 | 101 |
| 102 Punctuation_Dash = U_MASK(U_DASH_PUNCTUATION), | 102 Punctuation_Dash = U_MASK(U_DASH_PUNCTUATION), |
| 103 Punctuation_Open = U_MASK(U_START_PUNCTUATION), | 103 Punctuation_Open = U_MASK(U_START_PUNCTUATION), |
| 104 Punctuation_Close = U_MASK(U_END_PUNCTUATION), | 104 Punctuation_Close = U_MASK(U_END_PUNCTUATION), |
| 105 Punctuation_Connector = U_MASK(U_CONNECTOR_PUNCTUATION), | 105 Punctuation_Connector = U_MASK(U_CONNECTOR_PUNCTUATION), |
| 106 Punctuation_Other = U_MASK(U_OTHER_PUNCTUATION), | 106 Punctuation_Other = U_MASK(U_OTHER_PUNCTUATION), |
| 107 | 107 |
| 108 Symbol_Math = U_MASK(U_MATH_SYMBOL), | 108 Symbol_Math = U_MASK(U_MATH_SYMBOL), |
| 109 Symbol_Currency = U_MASK(U_CURRENCY_SYMBOL), | 109 Symbol_Currency = U_MASK(U_CURRENCY_SYMBOL), |
| 110 Symbol_Modifier = U_MASK(U_MODIFIER_SYMBOL), | 110 Symbol_Modifier = U_MASK(U_MODIFIER_SYMBOL), |
| 111 Symbol_Other = U_MASK(U_OTHER_SYMBOL), | 111 Symbol_Other = U_MASK(U_OTHER_SYMBOL), |
| 112 | 112 |
| 113 Punctuation_InitialQuote = U_MASK(U_INITIAL_PUNCTUATION), | 113 Punctuation_InitialQuote = U_MASK(U_INITIAL_PUNCTUATION), |
| 114 Punctuation_FinalQuote = U_MASK(U_FINAL_PUNCTUATION) | 114 Punctuation_FinalQuote = U_MASK(U_FINAL_PUNCTUATION) |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 inline UChar32 foldCase(UChar32 c) | 117 inline UChar32 foldCase(UChar32 c) { |
| 118 { | 118 return u_foldCase(c, U_FOLD_CASE_DEFAULT); |
| 119 return u_foldCase(c, U_FOLD_CASE_DEFAULT); | |
| 120 } | 119 } |
| 121 | 120 |
| 122 inline int foldCase(UChar* result, int resultLength, const UChar* src, int srcLe
ngth, bool* error) | 121 inline int foldCase(UChar* result, |
| 123 { | 122 int resultLength, |
| 124 UErrorCode status = U_ZERO_ERROR; | 123 const UChar* src, |
| 125 int realLength = u_strFoldCase(result, resultLength, src, srcLength, U_FOLD_
CASE_DEFAULT, &status); | 124 int srcLength, |
| 126 *error = !U_SUCCESS(status); | 125 bool* error) { |
| 127 return realLength; | 126 UErrorCode status = U_ZERO_ERROR; |
| 127 int realLength = u_strFoldCase(result, resultLength, src, srcLength, |
| 128 U_FOLD_CASE_DEFAULT, &status); |
| 129 *error = !U_SUCCESS(status); |
| 130 return realLength; |
| 128 } | 131 } |
| 129 | 132 |
| 130 inline int toLower(UChar* result, int resultLength, const UChar* src, int srcLen
gth, bool* error) | 133 inline int toLower(UChar* result, |
| 131 { | 134 int resultLength, |
| 132 UErrorCode status = U_ZERO_ERROR; | 135 const UChar* src, |
| 133 int realLength = u_strToLower(result, resultLength, src, srcLength, "", &sta
tus); | 136 int srcLength, |
| 134 *error = !!U_FAILURE(status); | 137 bool* error) { |
| 135 return realLength; | 138 UErrorCode status = U_ZERO_ERROR; |
| 139 int realLength = |
| 140 u_strToLower(result, resultLength, src, srcLength, "", &status); |
| 141 *error = !!U_FAILURE(status); |
| 142 return realLength; |
| 136 } | 143 } |
| 137 | 144 |
| 138 inline UChar32 toLower(UChar32 c) | 145 inline UChar32 toLower(UChar32 c) { |
| 139 { | 146 return u_tolower(c); |
| 140 return u_tolower(c); | |
| 141 } | 147 } |
| 142 | 148 |
| 143 inline UChar32 toUpper(UChar32 c) | 149 inline UChar32 toUpper(UChar32 c) { |
| 144 { | 150 return u_toupper(c); |
| 145 return u_toupper(c); | |
| 146 } | 151 } |
| 147 | 152 |
| 148 inline int toUpper(UChar* result, int resultLength, const UChar* src, int srcLen
gth, bool* error) | 153 inline int toUpper(UChar* result, |
| 149 { | 154 int resultLength, |
| 150 UErrorCode status = U_ZERO_ERROR; | 155 const UChar* src, |
| 151 int realLength = u_strToUpper(result, resultLength, src, srcLength, "", &sta
tus); | 156 int srcLength, |
| 152 *error = !!U_FAILURE(status); | 157 bool* error) { |
| 153 return realLength; | 158 UErrorCode status = U_ZERO_ERROR; |
| 159 int realLength = |
| 160 u_strToUpper(result, resultLength, src, srcLength, "", &status); |
| 161 *error = !!U_FAILURE(status); |
| 162 return realLength; |
| 154 } | 163 } |
| 155 | 164 |
| 156 inline UChar32 toTitleCase(UChar32 c) | 165 inline UChar32 toTitleCase(UChar32 c) { |
| 157 { | 166 return u_totitle(c); |
| 158 return u_totitle(c); | |
| 159 } | 167 } |
| 160 | 168 |
| 161 inline bool isArabicChar(UChar32 c) | 169 inline bool isArabicChar(UChar32 c) { |
| 162 { | 170 return ublock_getCode(c) == UBLOCK_ARABIC; |
| 163 return ublock_getCode(c) == UBLOCK_ARABIC; | |
| 164 } | 171 } |
| 165 | 172 |
| 166 inline bool isAlphanumeric(UChar32 c) | 173 inline bool isAlphanumeric(UChar32 c) { |
| 167 { | 174 return u_isalnum(c); |
| 168 return u_isalnum(c); | |
| 169 } | 175 } |
| 170 | 176 |
| 171 inline bool isSeparatorSpace(UChar32 c) | 177 inline bool isSeparatorSpace(UChar32 c) { |
| 172 { | 178 return u_charType(c) == U_SPACE_SEPARATOR; |
| 173 return u_charType(c) == U_SPACE_SEPARATOR; | |
| 174 } | 179 } |
| 175 | 180 |
| 176 inline bool isPrintableChar(UChar32 c) | 181 inline bool isPrintableChar(UChar32 c) { |
| 177 { | 182 return !!u_isprint(c); |
| 178 return !!u_isprint(c); | |
| 179 } | 183 } |
| 180 | 184 |
| 181 inline bool isPunct(UChar32 c) | 185 inline bool isPunct(UChar32 c) { |
| 182 { | 186 return !!u_ispunct(c); |
| 183 return !!u_ispunct(c); | |
| 184 } | 187 } |
| 185 | 188 |
| 186 inline bool hasLineBreakingPropertyComplexContext(UChar32 c) | 189 inline bool hasLineBreakingPropertyComplexContext(UChar32 c) { |
| 187 { | 190 return u_getIntPropertyValue(c, UCHAR_LINE_BREAK) == U_LB_COMPLEX_CONTEXT; |
| 188 return u_getIntPropertyValue(c, UCHAR_LINE_BREAK) == U_LB_COMPLEX_CONTEXT; | |
| 189 } | 191 } |
| 190 | 192 |
| 191 inline UChar32 mirroredChar(UChar32 c) | 193 inline UChar32 mirroredChar(UChar32 c) { |
| 192 { | 194 return u_charMirror(c); |
| 193 return u_charMirror(c); | |
| 194 } | 195 } |
| 195 | 196 |
| 196 inline CharCategory category(UChar32 c) | 197 inline CharCategory category(UChar32 c) { |
| 197 { | 198 return static_cast<CharCategory>(U_GET_GC_MASK(c)); |
| 198 return static_cast<CharCategory>(U_GET_GC_MASK(c)); | |
| 199 } | 199 } |
| 200 | 200 |
| 201 inline Direction direction(UChar32 c) | 201 inline Direction direction(UChar32 c) { |
| 202 { | 202 return static_cast<Direction>(u_charDirection(c)); |
| 203 return static_cast<Direction>(u_charDirection(c)); | |
| 204 } | 203 } |
| 205 | 204 |
| 206 inline bool isLower(UChar32 c) | 205 inline bool isLower(UChar32 c) { |
| 207 { | 206 return !!u_islower(c); |
| 208 return !!u_islower(c); | |
| 209 } | 207 } |
| 210 | 208 |
| 211 inline uint8_t combiningClass(UChar32 c) | 209 inline uint8_t combiningClass(UChar32 c) { |
| 212 { | 210 return u_getCombiningClass(c); |
| 213 return u_getCombiningClass(c); | |
| 214 } | 211 } |
| 215 | 212 |
| 216 inline DecompositionType decompositionType(UChar32 c) | 213 inline DecompositionType decompositionType(UChar32 c) { |
| 217 { | 214 return static_cast<DecompositionType>( |
| 218 return static_cast<DecompositionType>(u_getIntPropertyValue(c, UCHAR_DECOMPO
SITION_TYPE)); | 215 u_getIntPropertyValue(c, UCHAR_DECOMPOSITION_TYPE)); |
| 219 } | 216 } |
| 220 | 217 |
| 221 inline int umemcasecmp(const UChar* a, const UChar* b, int len) | 218 inline int umemcasecmp(const UChar* a, const UChar* b, int len) { |
| 222 { | 219 return u_memcasecmp(a, b, len, U_FOLD_CASE_DEFAULT); |
| 223 return u_memcasecmp(a, b, len, U_FOLD_CASE_DEFAULT); | |
| 224 } | 220 } |
| 225 | 221 |
| 226 } // namespace Unicode | 222 } // namespace Unicode |
| 227 | 223 |
| 228 } // namespace WTF | 224 } // namespace WTF |
| 229 | 225 |
| 230 #endif // WTF_UnicodeIcu_h | 226 #endif // WTF_UnicodeIcu_h |
| OLD | NEW |