File: unicode.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (190 lines) | stat: -rw-r--r-- 6,226 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 *  Copyright (C) 2006 George Staikos <staikos@kde.org>
 *  Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved.
 *  Copyright (C) 2007-2009 Torch Mobile, Inc.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 *
 */

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TEXT_UNICODE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TEXT_UNICODE_H_

#include <unicode/uchar.h>

#include "third_party/blink/renderer/platform/wtf/text/ascii_ctype.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_uchar.h"

namespace WTF {
namespace unicode {

enum CharDirection {
  kLeftToRight = U_LEFT_TO_RIGHT,
  kRightToLeft = U_RIGHT_TO_LEFT,
  kEuropeanNumber = U_EUROPEAN_NUMBER,
  kEuropeanNumberSeparator = U_EUROPEAN_NUMBER_SEPARATOR,
  kEuropeanNumberTerminator = U_EUROPEAN_NUMBER_TERMINATOR,
  kArabicNumber = U_ARABIC_NUMBER,
  kCommonNumberSeparator = U_COMMON_NUMBER_SEPARATOR,
  kBlockSeparator = U_BLOCK_SEPARATOR,
  kSegmentSeparator = U_SEGMENT_SEPARATOR,
  kWhiteSpaceNeutral = U_WHITE_SPACE_NEUTRAL,
  kOtherNeutral = U_OTHER_NEUTRAL,
  kLeftToRightEmbedding = U_LEFT_TO_RIGHT_EMBEDDING,
  kLeftToRightOverride = U_LEFT_TO_RIGHT_OVERRIDE,
  kRightToLeftArabic = U_RIGHT_TO_LEFT_ARABIC,
  kRightToLeftEmbedding = U_RIGHT_TO_LEFT_EMBEDDING,
  kRightToLeftOverride = U_RIGHT_TO_LEFT_OVERRIDE,
  kPopDirectionalFormat = U_POP_DIRECTIONAL_FORMAT,
  kNonSpacingMark = U_DIR_NON_SPACING_MARK,
  kBoundaryNeutral = U_BOUNDARY_NEUTRAL
};

enum CharDecompositionType {
  kDecompositionNone = U_DT_NONE,
  kDecompositionCanonical = U_DT_CANONICAL,
  kDecompositionCompat = U_DT_COMPAT,
  kDecompositionCircle = U_DT_CIRCLE,
  kDecompositionFinal = U_DT_FINAL,
  kDecompositionFont = U_DT_FONT,
  kDecompositionFraction = U_DT_FRACTION,
  kDecompositionInitial = U_DT_INITIAL,
  kDecompositionIsolated = U_DT_ISOLATED,
  kDecompositionMedial = U_DT_MEDIAL,
  kDecompositionNarrow = U_DT_NARROW,
  kDecompositionNoBreak = U_DT_NOBREAK,
  kDecompositionSmall = U_DT_SMALL,
  kDecompositionSquare = U_DT_SQUARE,
  kDecompositionSub = U_DT_SUB,
  kDecompositionSuper = U_DT_SUPER,
  kDecompositionVertical = U_DT_VERTICAL,
  kDecompositionWide = U_DT_WIDE,
};

enum CharCategory {
  kNoCategory = 0,
  kOther_NotAssigned = U_MASK(U_GENERAL_OTHER_TYPES),
  kLetter_Uppercase = U_MASK(U_UPPERCASE_LETTER),
  kLetter_Lowercase = U_MASK(U_LOWERCASE_LETTER),
  kLetter_Titlecase = U_MASK(U_TITLECASE_LETTER),
  kLetter_Modifier = U_MASK(U_MODIFIER_LETTER),
  kLetter_Other = U_MASK(U_OTHER_LETTER),

  kMark_NonSpacing = U_MASK(U_NON_SPACING_MARK),
  kMark_Enclosing = U_MASK(U_ENCLOSING_MARK),
  kMark_SpacingCombining = U_MASK(U_COMBINING_SPACING_MARK),

  kNumber_DecimalDigit = U_MASK(U_DECIMAL_DIGIT_NUMBER),
  kNumber_Letter = U_MASK(U_LETTER_NUMBER),
  kNumber_Other = U_MASK(U_OTHER_NUMBER),

  kSeparator_Space = U_MASK(U_SPACE_SEPARATOR),
  kSeparator_Line = U_MASK(U_LINE_SEPARATOR),
  kSeparator_Paragraph = U_MASK(U_PARAGRAPH_SEPARATOR),

  kOther_Control = U_MASK(U_CONTROL_CHAR),
  kOther_Format = U_MASK(U_FORMAT_CHAR),
  kOther_PrivateUse = U_MASK(U_PRIVATE_USE_CHAR),
  kOther_Surrogate = U_MASK(U_SURROGATE),

  kPunctuation_Dash = U_MASK(U_DASH_PUNCTUATION),
  kPunctuation_Open = U_MASK(U_START_PUNCTUATION),
  kPunctuation_Close = U_MASK(U_END_PUNCTUATION),
  kPunctuation_Connector = U_MASK(U_CONNECTOR_PUNCTUATION),
  kPunctuation_Other = U_MASK(U_OTHER_PUNCTUATION),

  kSymbol_Math = U_MASK(U_MATH_SYMBOL),
  kSymbol_Currency = U_MASK(U_CURRENCY_SYMBOL),
  kSymbol_Modifier = U_MASK(U_MODIFIER_SYMBOL),
  kSymbol_Other = U_MASK(U_OTHER_SYMBOL),

  kPunctuation_InitialQuote = U_MASK(U_INITIAL_PUNCTUATION),
  kPunctuation_FinalQuote = U_MASK(U_FINAL_PUNCTUATION)
};

inline UChar32 FoldCase(UChar32 c) {
  return u_foldCase(c, U_FOLD_CASE_DEFAULT);
}

inline UChar32 ToLower(UChar32 c) {
  return u_tolower(c);
}

inline UChar32 ToUpper(UChar32 c) {
  return u_toupper(c);
}

inline UChar32 ToTitleCase(UChar32 c) {
  return u_totitle(c);
}

inline bool IsAlphanumeric(UChar32 c) {
  return !!u_isalnum(c);
}

inline bool IsPrintableChar(UChar32 c) {
  return !!u_isprint(c);
}

inline bool IsPunct(UChar32 c) {
  return !!u_ispunct(c);
}

inline bool HasLineBreakingPropertyComplexContext(UChar32 c) {
  return u_getIntPropertyValue(c, UCHAR_LINE_BREAK) == U_LB_COMPLEX_CONTEXT;
}

inline CharCategory Category(UChar32 c) {
  return static_cast<CharCategory>(U_GET_GC_MASK(c));
}

inline bool IsSymbol(UChar32 c) {
  CharCategory char_category = Category(c);
  return char_category == kSymbol_Math || char_category == kSymbol_Currency ||
         char_category == kSymbol_Modifier || char_category == kSymbol_Other;
}

inline CharDirection Direction(UChar32 c) {
  return static_cast<CharDirection>(u_charDirection(c));
}

inline bool IsLower(UChar32 c) {
  return !!u_islower(c);
}

inline bool IsUpper(UChar32 c) {
  return !!u_isupper(c);
}

inline CharDecompositionType DecompositionType(UChar32 c) {
  return static_cast<CharDecompositionType>(
      u_getIntPropertyValue(c, UCHAR_DECOMPOSITION_TYPE));
}

inline bool IsSpaceOrNewline(UChar c) {
  // Use IsASCIISpace() for basic Latin-1.
  // This will include newlines, which aren't included in Unicode DirWS.
  return c <= 0x7F
             ? WTF::IsASCIISpace(c)
             : WTF::unicode::Direction(c) == WTF::unicode::kWhiteSpaceNeutral;
}

}  // namespace unicode
}  // namespace WTF

using WTF::unicode::IsSpaceOrNewline;

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TEXT_UNICODE_H_