summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstring.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago@kde.org>2011-07-21 16:33:17 +0200
committerQt by Nokia <qt-info@nokia.com>2011-07-21 18:56:02 +0200
commit001bd63e813cf19d1d6abbbfeb2599e6804807d5 (patch)
tree5f9947b973fca9e27a9f91628ba69405a51a89a5 /src/corelib/tools/qstring.h
parent74a6fe79d999178de9d16befe7547af2d2f9f698 (diff)
Make the N parameter to the QXXXLiterals be the actual string length
Before, it was the length + 1, to include the ending NUL or U+0000. This avoids mistakes of -1 in QStringBuilder and will allow us simpler code in the User-Defined Literal (future improvement) Change-Id: I75c47d6c44579124888f925e240817229347dc70 Merge-request: 31 Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com> Reviewed-on: http://codereview.qt.nokia.com/1966 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src/corelib/tools/qstring.h')
-rw-r--r--src/corelib/tools/qstring.h20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index af3e3f3ff9..4471da4b09 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -97,36 +97,36 @@ template<int N> struct QConstStringDataPtr
};
#if defined(Q_COMPILER_UNICODE_STRINGS)
-template<int n> struct QConstStringData
+template<int N> struct QConstStringData
{
const QStringData str;
- const char16_t data[n];
+ const char16_t data[N + 1];
};
#define QT_QSTRING_UNICODE_MARKER u""
#elif defined(Q_OS_WIN) || (defined(__SIZEOF_WCHAR_T__) && __SIZEOF_WCHAR_T__ == 2) || defined(WCHAR_MAX) && (WCHAR_MAX - 0 < 65536)
// wchar_t is 2 bytes
-template<int n> struct QConstStringData
+template<int N> struct QConstStringData
{
const QStringData str;
- const wchar_t data[n];
+ const wchar_t data[N + 1];
};
#define QT_QSTRING_UNICODE_MARKER L""
#else
-template<int n> struct QConstStringData
+template<int N> struct QConstStringData
{
const QStringData str;
- const ushort data[n];
+ const ushort data[N + 1];
};
#endif
#if defined(QT_QSTRING_UNICODE_MARKER)
# if defined(Q_COMPILER_LAMBDA)
# define QStringLiteral(str) ([]() { \
- enum { Size = sizeof(QT_QSTRING_UNICODE_MARKER str)/2 }; \
+ enum { Size = sizeof(QT_QSTRING_UNICODE_MARKER str)/2 - 1 }; \
static const QConstStringData<Size> qstring_literal = \
- { { Q_REFCOUNT_INITIALIZER(-1), Size -1, 0, 0, { 0 } }, QT_QSTRING_UNICODE_MARKER str }; \
+ { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, QT_QSTRING_UNICODE_MARKER str }; \
QConstStringDataPtr<Size> holder = { &qstring_literal }; \
return holder; }())
@@ -137,9 +137,9 @@ template<int n> struct QConstStringData
# define QStringLiteral(str) \
__extension__ ({ \
- enum { Size = sizeof(QT_QSTRING_UNICODE_MARKER str)/2 }; \
+ enum { Size = sizeof(QT_QSTRING_UNICODE_MARKER str)/2 - 1 }; \
static const QConstStringData<Size> qstring_literal = \
- { { Q_REFCOUNT_INITIALIZER(-1), Size -1, 0, 0, { 0 } }, QT_QSTRING_UNICODE_MARKER str }; \
+ { { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, QT_QSTRING_UNICODE_MARKER str }; \
QConstStringDataPtr<Size> holder = { &qstring_literal }; \
holder; })
# endif