summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2012-05-03 15:43:10 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-03 16:11:58 +0200
commit6dac3f18941bd2d66218ec43f08e4fb9be869c63 (patch)
treef2664c9f31d5046f38a1403f46eb0fc162d5242c /src/corelib/tools/qstring.h
parentb4dabb9e50ce26469b0b7d71e168463abf727334 (diff)
parent1e49914fee099c4c0d634743326b50ad02e6c8f1 (diff)
Merge "Merge remote-tracking branch 'origin/api_changes'" into refs/staging/master
Diffstat (limited to 'src/corelib/tools/qstring.h')
-rw-r--r--src/corelib/tools/qstring.h43
1 files changed, 16 insertions, 27 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 3d0de55ed7..bf2928346c 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -78,17 +78,7 @@ class QLatin1String;
class QStringRef;
template <typename T> class QVector;
-struct QStringData {
- QtPrivate::RefCount ref;
- int size;
- uint alloc : 31;
- uint capacityReserved : 1;
-
- qptrdiff offset;
-
- inline ushort *data() { return reinterpret_cast<ushort *>(reinterpret_cast<char *>(this) + offset); }
- inline const ushort *data() const { return reinterpret_cast<const ushort *>(reinterpret_cast<const char *>(this) + offset); }
-};
+typedef QTypedArrayData<ushort> QStringData;
#if defined(Q_COMPILER_UNICODE_STRINGS)
@@ -122,13 +112,14 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2,
# if defined(Q_COMPILER_LAMBDA)
# define QStringLiteral(str) \
- ([]() -> QStringDataPtr { \
+ ([]() -> QString { \
enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \
static const QStaticStringData<Size> qstring_literal = { \
Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \
QT_UNICODE_LITERAL(str) }; \
QStringDataPtr holder = { qstring_literal.data_ptr() }; \
- return holder; \
+ const QString s(holder); \
+ return s; \
}()) \
/**/
@@ -138,14 +129,14 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2,
// To do that, we need the __extension__ {( )} trick which only GCC supports
# define QStringLiteral(str) \
- __extension__ ({ \
+ QString(__extension__ ({ \
enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \
static const QStaticStringData<Size> qstring_literal = { \
Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \
QT_UNICODE_LITERAL(str) }; \
QStringDataPtr holder = { qstring_literal.data_ptr() }; \
holder; \
- }) \
+ })) \
/**/
# endif
@@ -153,9 +144,10 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2,
#ifndef QStringLiteral
// no lambdas, not GCC, or GCC in C++98 mode with 4-byte wchar_t
-// fallback, uses QLatin1String as next best options
+// fallback, return a temporary QString
+// source code is assumed to be encoded in UTF-8
-# define QStringLiteral(str) QLatin1String(str)
+# define QStringLiteral(str) QString::fromUtf8(str, sizeof(str) - 1)
#endif
#define Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) \
@@ -169,13 +161,13 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2,
template <int N>
struct QStaticStringData
{
- QStringData str;
+ QArrayData str;
qunicodechar data[N + 1];
QStringData *data_ptr() const
{
Q_ASSERT(str.ref.isStatic());
- return const_cast<QStringData *>(&str);
+ return const_cast<QStringData *>(static_cast<const QStringData*>(&str));
}
};
@@ -632,9 +624,9 @@ public:
// compatibility
struct Null { };
static const Null null;
- inline QString(const Null &): d(shared_null.data_ptr()) {}
+ inline QString(const Null &): d(Data::sharedNull()) {}
inline QString &operator=(const Null &) { *this = QString(); return *this; }
- inline bool isNull() const { return d == &shared_null.str; }
+ inline bool isNull() const { return d == Data::sharedNull(); }
bool isSimpleText() const;
@@ -653,11 +645,8 @@ private:
QString &operator=(const QByteArray &a);
#endif
- static const QStaticStringData<1> shared_null;
- static const QStaticStringData<1> shared_empty;
Data *d;
- static void free(Data *);
void reallocData(uint alloc, bool grow = false);
void expand(int i);
void updateProperties() const;
@@ -927,8 +916,8 @@ inline void QCharRef::setRow(uchar arow) { QChar(*this).setRow(arow); }
inline void QCharRef::setCell(uchar acell) { QChar(*this).setCell(acell); }
-inline QString::QString() : d(shared_null.data_ptr()) {}
-inline QString::~QString() { if (!d->ref.deref()) free(d); }
+inline QString::QString() : d(Data::sharedNull()) {}
+inline QString::~QString() { if (!d->ref.deref()) Data::deallocate(d); }
inline void QString::reserve(int asize)
{
@@ -1203,7 +1192,7 @@ public:
inline const QChar *unicode() const {
if (!m_string)
- return reinterpret_cast<const QChar *>(QString::shared_null.str.data());
+ return reinterpret_cast<const QChar *>(QString::Data::sharedNull()->data());
return m_string->unicode() + m_position;
}
inline const QChar *data() const { return unicode(); }