1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39#ifndef UNICODE_H
40#define UNICODE_H
41
42#include <QtCore/private/qunicodetables_p.h>
43#include <QtCore/qchar.h>
44
45typedef unsigned char LChar;
46typedef unsigned short UChar;
47typedef int32_t UChar32;
48
49namespace Unicode {
50 // u_tolower applies only Simple_Lowercase_Mapping. This is in contrast to QChar::toLower.
51 inline UChar32 u_tolower(UChar32 ch) {
52 if (ch > QChar::LastValidCodePoint)
53 return ch;
54 const auto fold = QUnicodeTables::properties(ucs4: char32_t(ch))->cases[QUnicodeTables::LowerCase];
55 return fold.special ? ch : (ch + fold.diff);
56 }
57
58 // u_toupper applies only Simple_Uppercase_Mapping. This is in contrast to QChar::toUpper.
59 inline UChar32 u_toupper(UChar32 ch) {
60 if (ch > QChar::LastValidCodePoint)
61 return ch;
62 const auto fold = QUnicodeTables::properties(ucs4: char32_t(ch))->cases[QUnicodeTables::UpperCase];
63 return fold.special ? ch : (ch + fold.diff);
64 }
65}
66
67using Unicode::u_toupper;
68using Unicode::u_tolower;
69
70#define U16_IS_LEAD(ch) QChar::isHighSurrogate((ch))
71#define U16_IS_TRAIL(ch) QChar::isLowSurrogate((ch))
72#define U16_GET_SUPPLEMENTARY(lead, trail) static_cast<UChar32>(QChar::surrogateToUcs4((lead), (trail)))
73#define U_IS_BMP(ch) ((ch) < 0x10000)
74#define U16_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2)
75#define UCHAR_MAX_VALUE 0x10ffff
76
77#define U_MASK(category) (1u << (category))
78#define U_GET_GC_MASK(c) U_MASK(QChar::category((c)))
79#define U_GC_L_MASK (U_GC_LU_MASK|U_GC_LL_MASK|U_GC_LT_MASK|U_GC_LM_MASK|U_GC_LO_MASK)
80#define U_GC_LU_MASK U_MASK(QChar::Letter_Uppercase)
81#define U_GC_LL_MASK U_MASK(QChar::Letter_Lowercase)
82#define U_GC_LT_MASK U_MASK(QChar::Letter_Titlecase)
83#define U_GC_LM_MASK U_MASK(QChar::Letter_Modifier)
84#define U_GC_LO_MASK U_MASK(QChar::Letter_Other)
85#define U_GC_MN_MASK U_MASK(QChar::Mark_NonSpacing)
86#define U_GC_MC_MASK U_MASK(QChar::Mark_SpacingCombining)
87#define U_GC_ND_MASK U_MASK(QChar::Number_DecimalDigit)
88#define U_GC_PC_MASK U_MASK(QChar::Punctuation_Connector)
89
90#endif // UNICODE_H
91

source code of qtdeclarative/src/3rdparty/masm/stubs/wtf/unicode/Unicode.h