diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qstringbuilder.cpp | 3 | ||||
-rw-r--r-- | src/corelib/tools/qstringbuilder.h | 52 |
2 files changed, 54 insertions, 1 deletions
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<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; |