diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-03-30 20:06:22 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2018-01-08 09:41:38 +0000 |
commit | 641e010cc7b52b6c3ac213e151781ffcbdd89145 (patch) | |
tree | b8128a654a2250ff8a8b891ac668b37bbf253744 /src/corelib/tools/qstringbuilder.h | |
parent | 6d0c8825f9bee01e4962a82d78a310e11ae8d17c (diff) |
QStringBuilder: add support for char16_t{,*,[]}
[ChangeLog][QtCore][QStringBuilder] Added support for char16_t
characters and strings.
Change-Id: Iee727f07226f2a326ae0df28d44930336cd8f71e
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/tools/qstringbuilder.h')
-rw-r--r-- | src/corelib/tools/qstringbuilder.h | 52 |
1 files changed, 52 insertions, 0 deletions
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<char> : private QAbstractConcatenable { *out++ = c; } }; +#if defined(Q_COMPILER_UNICODE_STRINGS) +template <> struct QConcatenable<char16_t> : 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<QLatin1Char> { typedef QLatin1Char type; @@ -325,6 +337,46 @@ template <> struct QConcatenable<char *> : QConcatenable<const char*> typedef char *type; }; +#if defined(Q_COMPILER_UNICODE_STRINGS) +template <int N> struct QConcatenable<const char16_t[N]> : 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 <int N> struct QConcatenable<char16_t[N]> : QConcatenable<const char16_t[N]> +{ + using type = char16_t[N]; +}; + +template <> struct QConcatenable<const char16_t *> : 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<char16_t *> : QConcatenable<const char16_t*> +{ + typedef char16_t *type; +}; +#endif // UNICODE_STRINGS + template <> struct QConcatenable<QByteArray> : private QAbstractConcatenable { typedef QByteArray type; |