/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QSTRINGBUILDER_H
#define QSTRINGBUILDER_H
+#if 0
+// syncqt can not handle the templates in this file, and it doesn't need to
+// process them anyway because they are internal.
+#pragma qt_class(QStringBuilder)
+#pragma qt_sync_stop_processing
+#endif
+
#include <QtCore/qstring.h>
#include <QtCore/qbytearray.h>
-#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL)
-# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ == 0)
-# include <QtCore/qmap.h>
-# endif
-#endif
-
#include <string.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-QT_MODULE(Core)
struct Q_CORE_EXPORT QAbstractConcatenable
{
protected:
static void convertFromAscii(const char *a, int len, QChar *&out);
- static void convertToAscii(const QChar *a, int len, char *&out);
static inline void convertFromAscii(char a, QChar *&out)
{
-#ifndef QT_NO_TEXTCODEC
- if (QString::codecForCStrings)
- *out++ = QChar::fromAscii(a);
- else
-#endif
- *out++ = QLatin1Char(a);
+ *out++ = QLatin1Char(a);
}
+};
- static inline void convertToAscii(QChar a, char *&out)
- {
-#ifndef QT_NO_TEXTCODEC
- if (QString::codecForCStrings)
- *out++ = a.toAscii(); //###
- else
-#endif
- convertToLatin1(a, out);
- }
+template <typename T> struct QConcatenable {};
- static inline void convertToLatin1(QChar a, char *&out)
- {
- *out++ = a.unicode() > 0xff ? '?' : char(a.unicode());
- }
+namespace QtStringBuilder {
+ template <typename A, typename B> struct ConvertToTypeHelper
+ { typedef A ConvertTo; };
+ template <typename T> struct ConvertToTypeHelper<T, QString>
+ { typedef QString ConvertTo; };
+}
+
+template<typename Builder, typename T>
+struct QStringBuilderCommon
+{
+ T toUpper() const { return resolved().toUpper(); }
+ T toLower() const { return resolved().toLower(); }
+
+protected:
+ const T resolved() const { return *static_cast<const Builder*>(this); }
};
-template <typename T> struct QConcatenable {};
+template<typename Builder, typename T>
+struct QStringBuilderBase : public QStringBuilderCommon<Builder, T>
+{
+};
+
+template<typename Builder>
+struct QStringBuilderBase<Builder, QString> : public QStringBuilderCommon<Builder, QString>
+{
+ QByteArray toLatin1() const { return this->resolved().toLatin1(); }
+ QByteArray toLocal8Bit() const { return this->resolved().toLocal8Bit(); }
+};
template <typename A, typename B>
-class QStringBuilder
+class QStringBuilder : public QStringBuilderBase<QStringBuilder<A, B>, typename QtStringBuilder::ConvertToTypeHelper<typename QConcatenable<A>::ConvertTo, typename QConcatenable<B>::ConvertTo>::ConvertTo>
{
public:
QStringBuilder(const A &a_, const B &b_) : a(a_), b(b_) {}
public:
operator ConvertTo() const { return convertTo<ConvertTo>(); }
- QByteArray toLatin1() const { return convertTo<QString>().toLatin1(); }
int size() const { return Concatenable::size(*this); }
const A &a;
};
template <>
-class QStringBuilder <QString, QString>
+class QStringBuilder <QString, QString> : public QStringBuilderBase<QStringBuilder<QString, QString>, QString>
{
public:
QStringBuilder(const QString &a_, const QString &b_) : a(a_), b(b_) {}
operator QString() const
{ QString r(a); r += b; return r; }
- QByteArray toLatin1() const { return QString(*this).toLatin1(); }
const QString &a;
const QString &b;
};
template <>
-class QStringBuilder <QByteArray, QByteArray>
+class QStringBuilder <QByteArray, QByteArray> : public QStringBuilderBase<QStringBuilder<QByteArray, QByteArray>, QByteArray>
{
public:
QStringBuilder(const QByteArray &a_, const QByteArray &b_) : a(a_), b(b_) {}
static int size(const QChar) { return 1; }
static inline void appendTo(const QChar c, QChar *&out)
{ *out++ = c; }
-#ifndef QT_NO_CAST_TO_ASCII
- static inline QT_ASCII_CAST_WARN void appendTo(const QChar c, char *&out)
- { convertToAscii(c, out); }
-#endif
+};
+
+template <> struct QConcatenable<QChar::SpecialCharacter> : private QAbstractConcatenable
+{
+ typedef QChar::SpecialCharacter type;
+ typedef QString ConvertTo;
+ enum { ExactSize = true };
+ static int size(const QChar::SpecialCharacter) { return 1; }
+ static inline void appendTo(const QChar::SpecialCharacter c, QChar *&out)
+ { *out++ = c; }
};
template <> struct QConcatenable<QCharRef> : private QAbstractConcatenable
static int size(const QCharRef &) { return 1; }
static inline void appendTo(const QCharRef &c, QChar *&out)
{ *out++ = QChar(c); }
-#ifndef QT_NO_CAST_TO_ASCII
- static inline QT_ASCII_CAST_WARN void appendTo(const QCharRef &c, char *&out)
- { convertToAscii(c, out); }
-#endif
};
template <> struct QConcatenable<QLatin1String>
memcpy(out, reinterpret_cast<const char*>(a.constData()), sizeof(QChar) * n);
out += n;
}
-#ifndef QT_NO_CAST_TO_ASCII
- static inline QT_ASCII_CAST_WARN void appendTo(const QString &a, char *&out)
- { convertToAscii(a.constData(), a.length(), out); }
-#endif
};
-template <int N> struct QConcatenable<QConstStringDataPtr<N> > : private QAbstractConcatenable
+template <> struct QConcatenable<QStringDataPtr> : private QAbstractConcatenable
{
- typedef QConstStringDataPtr<N> type;
+ typedef QStringDataPtr type;
typedef QString ConvertTo;
enum { ExactSize = true };
- static int size(const type &) { return N; }
+ static int size(const type &a) { return a.ptr->size; }
static inline void appendTo(const type &a, QChar *&out)
{
- memcpy(out, reinterpret_cast<const char*>(a.ptr->data), sizeof(QChar) * N);
- out += N;
+ memcpy(out, reinterpret_cast<const char*>(a.ptr->data()), sizeof(QChar) * a.ptr->size);
+ out += a.ptr->size;
}
-#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
memcpy(out, reinterpret_cast<const char*>(a.constData()), sizeof(QChar) * n);
out += n;
}
-#ifndef QT_NO_CAST_TO_ASCII
- static inline QT_ASCII_CAST_WARN void appendTo(const QStringRef &a, char *&out)
- { convertToAscii(a.constData(), a.length(), out); }
-#endif
-
};
template <int N> struct QConcatenable<char[N]> : private QAbstractConcatenable
}
};
-template <int N> struct QConcatenable<QConstByteArrayDataPtr<N> > : private QAbstractConcatenable
+template <> struct QConcatenable<QByteArrayDataPtr> : private QAbstractConcatenable
{
- typedef QConstByteArrayDataPtr<N> type;
+ typedef QByteArrayDataPtr type;
typedef QByteArray ConvertTo;
enum { ExactSize = false };
- static int size(const type &) { return N; }
+ static int size(const type &ba) { return ba.ptr->size; }
#ifndef QT_NO_CAST_FROM_ASCII
static inline QT_ASCII_CAST_WARN void appendTo(const type &a, QChar *&out)
{
- QAbstractConcatenable::convertFromAscii(a.ptr->data, N, out);
+ QAbstractConcatenable::convertFromAscii(a.ptr->data(), a.ptr->size, out);
}
#endif
static inline void appendTo(const type &ba, char *&out)
{
- const char *a = ba.ptr->data;
- while (*a)
- *out++ = *a++;
+ ::memcpy(out, ba.ptr->data(), ba.ptr->size);
+ out += ba.ptr->size;
}
};
-namespace QtStringBuilder {
- template <typename A, typename B> struct ConvertToTypeHelper
- { typedef A ConvertTo; };
- template <typename T> struct ConvertToTypeHelper<T, QString>
- { typedef QString ConvertTo; };
-}
-
template <typename A, typename B>
struct QConcatenable< QStringBuilder<A, B> >
{