| 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 <QChar> |
| 43 | |
| 44 | typedef unsigned char LChar; |
| 45 | typedef unsigned short UChar; |
| 46 | typedef int32_t UChar32; |
| 47 | |
| 48 | namespace Unicode { |
| 49 | inline UChar toLower(UChar ch) { |
| 50 | return QChar::toLower(ucs4: ch); |
| 51 | } |
| 52 | |
| 53 | inline UChar toUpper(UChar ch) { |
| 54 | return QChar::toUpper(ucs4: ch); |
| 55 | } |
| 56 | inline UChar32 u_tolower(UChar32 ch) { |
| 57 | return QChar::toLower(ucs4: ch); |
| 58 | } |
| 59 | inline UChar32 u_toupper(UChar32 ch) { |
| 60 | return QChar::toUpper(ucs4: ch); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | using Unicode::u_toupper; |
| 65 | using Unicode::u_tolower; |
| 66 | |
| 67 | #define U16_IS_LEAD(ch) QChar::isHighSurrogate((ch)) |
| 68 | #define U16_IS_TRAIL(ch) QChar::isLowSurrogate((ch)) |
| 69 | #define U16_GET_SUPPLEMENTARY(lead, trail) static_cast<UChar32>(QChar::surrogateToUcs4((lead), (trail))) |
| 70 | #define U_IS_BMP(ch) ((ch) < 0x10000) |
| 71 | #define U16_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2) |
| 72 | #define UCHAR_MAX_VALUE 0x10ffff |
| 73 | |
| 74 | #define U_MASK(category) (1u << (category)) |
| 75 | #define U_GET_GC_MASK(c) U_MASK(QChar::category((c))) |
| 76 | #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) |
| 77 | #define U_GC_LU_MASK U_MASK(QChar::Letter_Uppercase) |
| 78 | #define U_GC_LL_MASK U_MASK(QChar::Letter_Lowercase) |
| 79 | #define U_GC_LT_MASK U_MASK(QChar::Letter_Titlecase) |
| 80 | #define U_GC_LM_MASK U_MASK(QChar::Letter_Modifier) |
| 81 | #define U_GC_LO_MASK U_MASK(QChar::Letter_Other) |
| 82 | #define U_GC_MN_MASK U_MASK(QChar::Mark_NonSpacing) |
| 83 | #define U_GC_MC_MASK U_MASK(QChar::Mark_SpacingCombining) |
| 84 | #define U_GC_ND_MASK U_MASK(QChar::Number_DecimalDigit) |
| 85 | #define U_GC_PC_MASK U_MASK(QChar::Punctuation_Connector) |
| 86 | |
| 87 | #endif // UNICODE_H |
| 88 | |