diff options
Diffstat (limited to 'src/corelib/tools/qstringbuilder.h')
-rw-r--r-- | src/corelib/tools/qstringbuilder.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 5c6d990314..1d96d70637 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; @@ -277,6 +289,20 @@ template <> struct QConcatenable<QStringRef> : private QAbstractConcatenable } }; +template <> struct QConcatenable<QStringView> : private QAbstractConcatenable +{ + typedef QStringView type; + typedef QString ConvertTo; + enum { ExactSize = true }; + static int size(QStringView a) { return a.length(); } + static inline void appendTo(QStringView a, QChar *&out) + { + const auto n = a.size(); + memcpy(out, a.data(), sizeof(QChar) * n); + out += n; + } +}; + template <int N> struct QConcatenable<const char[N]> : private QAbstractConcatenable { typedef const char type[N]; @@ -325,6 +351,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; |