From 641e010cc7b52b6c3ac213e151781ffcbdd89145 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 30 Mar 2017 20:06:22 +0200 Subject: QStringBuilder: add support for char16_t{,*,[]} [ChangeLog][QtCore][QStringBuilder] Added support for char16_t characters and strings. Change-Id: Iee727f07226f2a326ae0df28d44930336cd8f71e Reviewed-by: Milian Wolff Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Edward Welbourne --- src/corelib/tools/qstringbuilder.cpp | 3 ++- src/corelib/tools/qstringbuilder.h | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/tools/qstringbuilder.cpp b/src/corelib/tools/qstringbuilder.cpp index 8300da30c2..37b0e08caf 100644 --- a/src/corelib/tools/qstringbuilder.cpp +++ b/src/corelib/tools/qstringbuilder.cpp @@ -74,8 +74,9 @@ QT_BEGIN_NAMESPACE \list \li QString, QStringRef, - \li QChar, QCharRef, QLatin1Char, + \li QChar, QCharRef, QLatin1Char, (since 5.10:) \c char16_t, \li QLatin1String, + \li (since 5.10:) \c{const char16_t[]} (\c{u"foo"}), \li QByteArray, \c char, \c{const char[]}. \endlist diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 5c6d990314..e9ca2245ba 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -187,6 +187,18 @@ template <> struct QConcatenable : private QAbstractConcatenable { *out++ = c; } }; +#if defined(Q_COMPILER_UNICODE_STRINGS) +template <> struct QConcatenable : private QAbstractConcatenable +{ + typedef char16_t type; + typedef QString ConvertTo; + enum { ExactSize = true }; + static Q_DECL_CONSTEXPR int size(char16_t) { return 1; } + static inline void appendTo(char16_t c, QChar *&out) + { *out++ = c; } +}; +#endif + template <> struct QConcatenable { typedef QLatin1Char type; @@ -325,6 +337,46 @@ template <> struct QConcatenable : QConcatenable typedef char *type; }; +#if defined(Q_COMPILER_UNICODE_STRINGS) +template struct QConcatenable : private QAbstractConcatenable +{ + using type = const char16_t[N]; + using ConvertTo = QString; + enum { ExactSize = true }; + static int size(const char16_t[N]) { return N - 1; } + static void appendTo(const char16_t a[N], QChar *&out) + { + memcpy(out, a, (N - 1) * sizeof(char16_t)); + out += N - 1; + } +}; + +template struct QConcatenable : QConcatenable +{ + using type = char16_t[N]; +}; + +template <> struct QConcatenable : private QAbstractConcatenable +{ + using type = const char16_t *; + using ConvertTo = QString; + enum { ExactSize = true }; + static int size(const char16_t *a) { return QStringView(a).length(); }; + static inline void QT_ASCII_CAST_WARN appendTo(const char16_t *a, QChar *&out) + { + if (!a) + return; + while (*a) + *out++ = *a++; + } +}; + +template <> struct QConcatenable : QConcatenable +{ + typedef char16_t *type; +}; +#endif // UNICODE_STRINGS + template <> struct QConcatenable : private QAbstractConcatenable { typedef QByteArray type; -- cgit v1.2.3