diff options
Diffstat (limited to 'src/corelib/tools/qstringbuilder.h')
-rw-r--r-- | src/corelib/tools/qstringbuilder.h | 55 |
1 files changed, 19 insertions, 36 deletions
diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 594ab2f183..6d998b62aa 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -59,22 +59,6 @@ QT_BEGIN_NAMESPACE QT_MODULE(Core) -// ### Qt 5: merge with QLatin1String -class QLatin1Literal -{ -public: - int size() const { return m_size; } - const char *data() const { return m_data; } - - template <int N> - QLatin1Literal(const char (&str)[N]) - : m_size(N - 1), m_data(str) {} - -private: - const int m_size; - const char * const m_data; -}; - struct Q_CORE_EXPORT QAbstractConcatenable { protected: @@ -234,31 +218,13 @@ template <> struct QConcatenable<QLatin1String> typedef QLatin1String type; typedef QString ConvertTo; enum { ExactSize = true }; - static int size(const QLatin1String &a) { return qstrlen(a.latin1()); } + static int size(const QLatin1String &a) { return a.size(); } static inline void appendTo(const QLatin1String &a, QChar *&out) { - for (const char *s = a.latin1(); *s; ) - *out++ = QLatin1Char(*s++); - } - static inline void appendTo(const QLatin1String &a, char *&out) - { - for (const char *s = a.latin1(); *s; ) - *out++ = *s++; - } -}; - -template <> struct QConcatenable<QLatin1Literal> -{ - typedef QLatin1Literal type; - typedef QString ConvertTo; - enum { ExactSize = true }; - static int size(const QLatin1Literal &a) { return a.size(); } - static inline void appendTo(const QLatin1Literal &a, QChar *&out) - { for (const char *s = a.data(); *s; ) *out++ = QLatin1Char(*s++); } - static inline void appendTo(const QLatin1Literal &a, char *&out) + static inline void appendTo(const QLatin1String &a, char *&out) { for (const char *s = a.data(); *s; ) *out++ = *s++; @@ -283,6 +249,23 @@ template <> struct QConcatenable<QString> : private QAbstractConcatenable #endif }; +template <int N> struct QConcatenable<QConstStringDataPtr<N> > : private QAbstractConcatenable +{ + typedef QConstStringDataPtr<N> type; + typedef QString ConvertTo; + enum { ExactSize = true }; + static int size(const type &) { return N; } + static inline void appendTo(const type &a, QChar *&out) + { + memcpy(out, reinterpret_cast<const char*>(a.ptr->data), sizeof(QChar) * N); + out += N; + } +#ifndef QT_NO_CAST_TO_ASCII + static inline QT_ASCII_CAST_WARN void appendTo(const type &a, char *&out) + { convertToAscii(a.ptr->data, N, out); } +#endif +}; + template <> struct QConcatenable<QStringRef> : private QAbstractConcatenable { typedef QStringRef type; |