summaryrefslogtreecommitdiff
path: root/src/3rdparty/javascriptcore/JavaScriptCore/wtf/unicode/glib/UnicodeGLib.h
blob: d72e707abcd46c9494480835b8d722aed4c84424 (plain)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
 *  Copyright (C) 2006 George Staikos <staikos@kde.org>
 *  Copyright (C) 2006 Alexey Proskuryakov <ap@nypop.com>
 *  Copyright (C) 2007 Apple Computer, Inc. All rights reserved.
 *  Copyright (C) 2008 Jürg Billeter <j@bitron.ch>
 *  Copyright (C) 2008 Dominik Röttsches <dominik.roettsches@access-company.com>
 *
 *  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 UnicodeGLib_h
#define UnicodeGLib_h

#include "UnicodeMacrosFromICU.h"
#include <wtf/gtk/GOwnPtr.h>

#include <glib.h>
#include <pango/pango.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

typedef uint16_t UChar;
typedef int32_t UChar32;

namespace WTF {
namespace Unicode {

enum Direction {
    LeftToRight,
    RightToLeft,
    EuropeanNumber,
    EuropeanNumberSeparator,
    EuropeanNumberTerminator,
    ArabicNumber,
    CommonNumberSeparator,
    BlockSeparator,
    SegmentSeparator,
    WhiteSpaceNeutral,
    OtherNeutral,
    LeftToRightEmbedding,
    LeftToRightOverride,
    RightToLeftArabic,
    RightToLeftEmbedding,
    RightToLeftOverride,
    PopDirectionalFormat,
    NonSpacingMark,
    BoundaryNeutral
};

enum DecompositionType {
    DecompositionNone,
    DecompositionCanonical,
    DecompositionCompat,
    DecompositionCircle,
    DecompositionFinal,
    DecompositionFont,
    DecompositionFraction,
    DecompositionInitial,
    DecompositionIsolated,
    DecompositionMedial,
    DecompositionNarrow,
    DecompositionNoBreak,
    DecompositionSmall,
    DecompositionSquare,
    DecompositionSub,
    DecompositionSuper,
    DecompositionVertical,
    DecompositionWide,
};

enum CharCategory {
    NoCategory =  0,
    Other_NotAssigned = U_MASK(G_UNICODE_UNASSIGNED),
    Letter_Uppercase = U_MASK(G_UNICODE_UPPERCASE_LETTER),
    Letter_Lowercase = U_MASK(G_UNICODE_LOWERCASE_LETTER),
    Letter_Titlecase = U_MASK(G_UNICODE_TITLECASE_LETTER),
    Letter_Modifier = U_MASK(G_UNICODE_MODIFIER_LETTER),
    Letter_Other = U_MASK(G_UNICODE_OTHER_LETTER),

    Mark_NonSpacing = U_MASK(G_UNICODE_NON_SPACING_MARK),
    Mark_Enclosing = U_MASK(G_UNICODE_ENCLOSING_MARK),
    Mark_SpacingCombining = U_MASK(G_UNICODE_COMBINING_MARK),

    Number_DecimalDigit = U_MASK(G_UNICODE_DECIMAL_NUMBER),
    Number_Letter = U_MASK(G_UNICODE_LETTER_NUMBER),
    Number_Other = U_MASK(G_UNICODE_OTHER_NUMBER),

    Separator_Space = U_MASK(G_UNICODE_SPACE_SEPARATOR),
    Separator_Line = U_MASK(G_UNICODE_LINE_SEPARATOR),
    Separator_Paragraph = U_MASK(G_UNICODE_PARAGRAPH_SEPARATOR),

    Other_Control = U_MASK(G_UNICODE_CONTROL),
    Other_Format = U_MASK(G_UNICODE_FORMAT),
    Other_PrivateUse = U_MASK(G_UNICODE_PRIVATE_USE),
    Other_Surrogate = U_MASK(G_UNICODE_SURROGATE),

    Punctuation_Dash = U_MASK(G_UNICODE_DASH_PUNCTUATION),
    Punctuation_Open = U_MASK(G_UNICODE_OPEN_PUNCTUATION),
    Punctuation_Close = U_MASK(G_UNICODE_CLOSE_PUNCTUATION),
    Punctuation_Connector = U_MASK(G_UNICODE_CONNECT_PUNCTUATION),
    Punctuation_Other = U_MASK(G_UNICODE_OTHER_PUNCTUATION),

    Symbol_Math = U_MASK(G_UNICODE_MATH_SYMBOL),
    Symbol_Currency = U_MASK(G_UNICODE_CURRENCY_SYMBOL),
    Symbol_Modifier = U_MASK(G_UNICODE_MODIFIER_SYMBOL),
    Symbol_Other = U_MASK(G_UNICODE_OTHER_SYMBOL),

    Punctuation_InitialQuote = U_MASK(G_UNICODE_INITIAL_PUNCTUATION),
    Punctuation_FinalQuote = U_MASK(G_UNICODE_FINAL_PUNCTUATION)
};

UChar32 foldCase(UChar32);

int foldCase(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error);

int toLower(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error);

inline UChar32 toLower(UChar32 c)
{
    return g_unichar_tolower(c);
}

inline UChar32 toUpper(UChar32 c)
{
    return g_unichar_toupper(c);
}

int toUpper(UChar* result, int resultLength, const UChar* src, int srcLength, bool* error);

inline UChar32 toTitleCase(UChar32 c)
{
    return g_unichar_totitle(c);
}

inline bool isArabicChar(UChar32 c)
{
    return c >= 0x0600 && c <= 0x06FF;
}

inline bool isAlphanumeric(UChar32 c)
{
    return g_unichar_isalnum(c);
}

inline bool isFormatChar(UChar32 c)
{
    return g_unichar_type(c) == G_UNICODE_FORMAT;
}

inline bool isSeparatorSpace(UChar32 c)
{
    return g_unichar_type(c) == G_UNICODE_SPACE_SEPARATOR;
}

inline bool isPrintableChar(UChar32 c)
{
    return g_unichar_isprint(c);
}

inline bool isDigit(UChar32 c)
{
    return g_unichar_isdigit(c);
}

inline bool isPunct(UChar32 c)
{
    return g_unichar_ispunct(c);
}

inline bool hasLineBreakingPropertyComplexContext(UChar32 c)
{
    // FIXME
    return false;
}

inline bool hasLineBreakingPropertyComplexContextOrIdeographic(UChar32 c)
{
    // FIXME
    return false;
}

inline UChar32 mirroredChar(UChar32 c)
{
    gunichar mirror = 0;
    g_unichar_get_mirror_char(c, &mirror);
    return mirror;
}

inline CharCategory category(UChar32 c)
{
    if (c > 0xffff)
        return NoCategory;

    return (CharCategory) U_MASK(g_unichar_type(c));
}

Direction direction(UChar32);

inline bool isLower(UChar32 c)
{
    return g_unichar_islower(c);
}

inline int digitValue(UChar32 c)
{
    return g_unichar_digit_value(c);
}

inline uint8_t combiningClass(UChar32 c)
{
    // FIXME
    // return g_unichar_combining_class(c);
    return 0;
}

inline DecompositionType decompositionType(UChar32 c)
{
    // FIXME
    return DecompositionNone;
}

int umemcasecmp(const UChar*, const UChar*, int len);

}
}

#endif