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>
This commit is contained in:
parent
74a6fe79d9
commit
001bd63e81
@ -133,10 +133,10 @@ struct QByteArrayData
|
|||||||
inline const char *data() const { return d + sizeof(qptrdiff) + offset; }
|
inline const char *data() const { return d + sizeof(qptrdiff) + offset; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<int n> struct QConstByteArrayData
|
template<int N> struct QConstByteArrayData
|
||||||
{
|
{
|
||||||
const QByteArrayData ba;
|
const QByteArrayData ba;
|
||||||
const char data[n];
|
const char data[N + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
template<int N> struct QConstByteArrayDataPtr
|
template<int N> struct QConstByteArrayDataPtr
|
||||||
@ -147,9 +147,9 @@ template<int N> struct QConstByteArrayDataPtr
|
|||||||
|
|
||||||
#if defined(Q_COMPILER_LAMBDA)
|
#if defined(Q_COMPILER_LAMBDA)
|
||||||
# define QByteArrayLiteral(str) ([]() { \
|
# define QByteArrayLiteral(str) ([]() { \
|
||||||
enum { Size = sizeof(str) }; \
|
enum { Size = sizeof(str) - 1 }; \
|
||||||
static const QConstByteArrayData<Size> qbytearray_literal = \
|
static const QConstByteArrayData<Size> qbytearray_literal = \
|
||||||
{ { Q_REFCOUNT_INITIALIZER(-1), Size -1, 0, 0, { 0 } }, str }; \
|
{ { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, str }; \
|
||||||
QConstByteArrayDataPtr<Size> holder = { &qbytearray_literal }; \
|
QConstByteArrayDataPtr<Size> holder = { &qbytearray_literal }; \
|
||||||
return holder; }())
|
return holder; }())
|
||||||
|
|
||||||
@ -160,9 +160,9 @@ template<int N> struct QConstByteArrayDataPtr
|
|||||||
|
|
||||||
# define QByteArrayLiteral(str) \
|
# define QByteArrayLiteral(str) \
|
||||||
__extension__ ({ \
|
__extension__ ({ \
|
||||||
enum { Size = sizeof(str) }; \
|
enum { Size = sizeof(str) - 1 }; \
|
||||||
static const QConstByteArrayData<Size> qbytearray_literal = \
|
static const QConstByteArrayData<Size> qbytearray_literal = \
|
||||||
{ { Q_REFCOUNT_INITIALIZER(-1), Size -1, 0, 0, { 0 } }, str }; \
|
{ { Q_REFCOUNT_INITIALIZER(-1), Size, 0, 0, { 0 } }, str }; \
|
||||||
QConstByteArrayDataPtr<Size> holder = { &qbytearray_literal }; \
|
QConstByteArrayDataPtr<Size> holder = { &qbytearray_literal }; \
|
||||||
holder; })
|
holder; })
|
||||||
#endif
|
#endif
|
||||||
|
@ -97,36 +97,36 @@ template<int N> struct QConstStringDataPtr
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if defined(Q_COMPILER_UNICODE_STRINGS)
|
#if defined(Q_COMPILER_UNICODE_STRINGS)
|
||||||
template<int n> struct QConstStringData
|
template<int N> struct QConstStringData
|
||||||
{
|
{
|
||||||
const QStringData str;
|
const QStringData str;
|
||||||
const char16_t data[n];
|
const char16_t data[N + 1];
|
||||||
};
|
};
|
||||||
#define QT_QSTRING_UNICODE_MARKER u""
|
#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)
|
#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
|
// wchar_t is 2 bytes
|
||||||
template<int n> struct QConstStringData
|
template<int N> struct QConstStringData
|
||||||
{
|
{
|
||||||
const QStringData str;
|
const QStringData str;
|
||||||
const wchar_t data[n];
|
const wchar_t data[N + 1];
|
||||||
};
|
};
|
||||||
#define QT_QSTRING_UNICODE_MARKER L""
|
#define QT_QSTRING_UNICODE_MARKER L""
|
||||||
|
|
||||||
#else
|
#else
|
||||||
template<int n> struct QConstStringData
|
template<int N> struct QConstStringData
|
||||||
{
|
{
|
||||||
const QStringData str;
|
const QStringData str;
|
||||||
const ushort data[n];
|
const ushort data[N + 1];
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(QT_QSTRING_UNICODE_MARKER)
|
#if defined(QT_QSTRING_UNICODE_MARKER)
|
||||||
# if defined(Q_COMPILER_LAMBDA)
|
# if defined(Q_COMPILER_LAMBDA)
|
||||||
# define QStringLiteral(str) ([]() { \
|
# 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 = \
|
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 }; \
|
QConstStringDataPtr<Size> holder = { &qstring_literal }; \
|
||||||
return holder; }())
|
return holder; }())
|
||||||
|
|
||||||
@ -137,9 +137,9 @@ template<int n> struct QConstStringData
|
|||||||
|
|
||||||
# define QStringLiteral(str) \
|
# define QStringLiteral(str) \
|
||||||
__extension__ ({ \
|
__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 = \
|
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 }; \
|
QConstStringDataPtr<Size> holder = { &qstring_literal }; \
|
||||||
holder; })
|
holder; })
|
||||||
# endif
|
# endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user