| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | #ifndef UNICODE_H |
| 4 | #define UNICODE_H |
| 5 | |
| 6 | #include <QtCore/private/qunicodetables_p.h> |
| 7 | #include <QtCore/qchar.h> |
| 8 | |
| 9 | typedef unsigned char LChar; |
| 10 | typedef unsigned short UChar; |
| 11 | typedef int32_t UChar32; |
| 12 | |
| 13 | namespace Unicode { |
| 14 | // u_tolower applies only Simple_Lowercase_Mapping. This is in contrast to QChar::toLower. |
| 15 | inline UChar32 u_tolower(UChar32 ch) { |
| 16 | if (ch > QChar::LastValidCodePoint) |
| 17 | return ch; |
| 18 | const auto fold = QUnicodeTables::properties(ucs4: char32_t(ch))->cases[QUnicodeTables::LowerCase]; |
| 19 | return fold.special ? ch : (ch + fold.diff); |
| 20 | } |
| 21 | |
| 22 | // u_toupper applies only Simple_Uppercase_Mapping. This is in contrast to QChar::toUpper. |
| 23 | inline UChar32 u_toupper(UChar32 ch) { |
| 24 | if (ch > QChar::LastValidCodePoint) |
| 25 | return ch; |
| 26 | const auto fold = QUnicodeTables::properties(ucs4: char32_t(ch))->cases[QUnicodeTables::UpperCase]; |
| 27 | return fold.special ? ch : (ch + fold.diff); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | using Unicode::u_toupper; |
| 32 | using Unicode::u_tolower; |
| 33 | |
| 34 | #define U16_IS_LEAD(ch) QChar::isHighSurrogate((ch)) |
| 35 | #define U16_IS_TRAIL(ch) QChar::isLowSurrogate((ch)) |
| 36 | #define U16_GET_SUPPLEMENTARY(lead, trail) static_cast<UChar32>(QChar::surrogateToUcs4((lead), (trail))) |
| 37 | #define U_IS_BMP(ch) ((ch) < 0x10000) |
| 38 | #define U16_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2) |
| 39 | #define UCHAR_MAX_VALUE 0x10ffff |
| 40 | |
| 41 | #define U_MASK(category) (1u << (category)) |
| 42 | #define U_GET_GC_MASK(c) U_MASK(QChar::category((c))) |
| 43 | #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) |
| 44 | #define U_GC_LU_MASK U_MASK(QChar::Letter_Uppercase) |
| 45 | #define U_GC_LL_MASK U_MASK(QChar::Letter_Lowercase) |
| 46 | #define U_GC_LT_MASK U_MASK(QChar::Letter_Titlecase) |
| 47 | #define U_GC_LM_MASK U_MASK(QChar::Letter_Modifier) |
| 48 | #define U_GC_LO_MASK U_MASK(QChar::Letter_Other) |
| 49 | #define U_GC_MN_MASK U_MASK(QChar::Mark_NonSpacing) |
| 50 | #define U_GC_MC_MASK U_MASK(QChar::Mark_SpacingCombining) |
| 51 | #define U_GC_ND_MASK U_MASK(QChar::Number_DecimalDigit) |
| 52 | #define U_GC_PC_MASK U_MASK(QChar::Punctuation_Connector) |
| 53 | |
| 54 | #endif // UNICODE_H |
| 55 | |