diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2020-04-29 11:36:19 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-05-09 06:26:08 +0000 |
commit | 928d57d8da5e89d2dd7fb3be8c992422538f47d0 (patch) | |
tree | 0915a02f6788300fd2d4d41bf1433ce7836021f8 /src/corelib/text/qchar.h | |
parent | 19e7c0d2b5a807e194be1d65b16041f48136c9be (diff) |
QChar: add fromUcs{2,4}()
The fromUcs2() named ctor is designed to replace all the non-char
integral-type constructors of QChar which make it very hard to control
the implicit QChar conversions, which have caused a few bugs in Qt
itself. As a classical named contructor, it simply returns QChar.
The fromUcs4() named "ctor", however, needs to expand surrogate pairs,
and thus can't just return QChar. Instead, it returns a small struct
that contains one or two char16_t's, can be iterated over and be
implicitly converted to QStringView. To avoid bikeshedding the name
(FromUcs4Result, of course :), it's defined inline and thus can't be
named outside the function. This function replaces most uses of
QChar::requiresSurrogates() in QtBase.
[ChangeLog][QtCore][QChar] Added fromUcs2(), fromUcs4().
Change-Id: I803708c14001040f75cb599e33c24a3fb8d2579c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qchar.h')
-rw-r--r-- | src/corelib/text/qchar.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/corelib/text/qchar.h b/src/corelib/text/qchar.h index ea1ce1e4bb..9fea104ec1 100644 --- a/src/corelib/text/qchar.h +++ b/src/corelib/text/qchar.h @@ -120,6 +120,10 @@ public: QT_ASCII_CAST_WARN Q_DECL_CONSTEXPR QChar(uchar c) noexcept : ucs(c) { } #endif #endif + + static constexpr QChar fromUcs2(char16_t c) noexcept { return QChar{c}; } + static constexpr inline auto fromUcs4(char32_t c) noexcept; + // Unicode information enum Category @@ -680,3 +684,5 @@ struct hash<QT_PREPEND_NAMESPACE(QChar)> } // namespace std #endif // QCHAR_H + +#include <QtCore/qstringview.h> // for QChar::fromUcs4() definition |