summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-03-14 01:00:21 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2019-03-14 10:49:29 +0100
commit32084b073362e52df597cc388cf54f5173e20b0d (patch)
tree9a6f881f0ab0bc22e3a491fae81d494815cc514f /src/corelib/tools
parent8d4e8217fdc01417ab8ea33303dd0ce7f769d10e (diff)
parenteb25acc05b177c49eb81b190a476854fbf3c6fb1 (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Conflicts: src/corelib/tools/qcollator_win.cpp Change-Id: I6d806d7c58b2057ebde3ad915bb5551f34b700e5
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbytearray.cpp19
-rw-r--r--src/corelib/tools/qcollator_win.cpp34
-rw-r--r--src/corelib/tools/qscopeguard.qdoc2
-rw-r--r--src/corelib/tools/qstring.cpp26
4 files changed, 50 insertions, 31 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 8770100749..8bf20350d6 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -523,7 +523,7 @@ int qstrnicmp(const char *str1, const char *str2, uint len)
A helper for QByteArray::compare. Compares \a len1 bytes from \a str1 to \a
len2 bytes from \a str2. If \a len2 is -1, then \a str2 is expected to be
- null-terminated.
+ '\\0'-terminated.
*/
int qstrnicmp(const char *str1, qsizetype len1, const char *str2, qsizetype len2)
{
@@ -1765,9 +1765,10 @@ void QByteArray::chop(int n)
If \a data is 0, a null byte array is constructed.
- If \a size is negative, \a data is assumed to point to a nul-terminated
- string and its length is determined dynamically. The terminating
- nul-character is not considered part of the byte array.
+ If \a size is negative, \a data is assumed to point to a
+ '\\0'-terminated string and its length is determined dynamically.
+ The terminating \\0 character is not considered part of the
+ byte array.
QByteArray makes a deep copy of the string data.
@@ -1924,7 +1925,7 @@ void QByteArray::expand(int i)
/*!
\internal
- Return a QByteArray that is sure to be NUL-terminated.
+ Return a QByteArray that is sure to be '\\0'-terminated.
By default, all QByteArray have an extra NUL at the end,
guaranteeing that assumption. However, if QByteArray::fromRawData
@@ -2336,8 +2337,8 @@ QByteArray &QByteArray::replace(int pos, int len, const QByteArray &after)
\overload
- Replaces \a len bytes from index position \a pos with the zero terminated
- string \a after.
+ Replaces \a len bytes from index position \a pos with the
+ '\\0'-terminated string \a after.
Notice: this can change the length of the byte array.
*/
@@ -2415,7 +2416,7 @@ QByteArray &QByteArray::replace(const char *c, const QByteArray &after)
Replaces every occurrence of the string \a before with the string \a after.
Since the sizes of the strings are given by \a bsize and \a asize, they
- may contain zero characters and do not need to be zero-terminated.
+ may contain zero characters and do not need to be '\\0'-terminated.
*/
QByteArray &QByteArray::replace(const char *before, int bsize, const char *after, int asize)
@@ -4540,7 +4541,7 @@ QByteArray QByteArray::number(double n, char f, int prec)
\snippet code/src_corelib_tools_qbytearray.cpp 43
\warning A byte array created with fromRawData() is \e not
- null-terminated, unless the raw data contains a 0 character at
+ '\\0'-terminated, unless the raw data contains a 0 character at
position \a size. While that does not matter for QDataStream or
functions like indexOf(), passing the byte array to a function
accepting a \c{const char *} expected to be '\\0'-terminated will
diff --git a/src/corelib/tools/qcollator_win.cpp b/src/corelib/tools/qcollator_win.cpp
index 4adbf4adf8..9d81de882f 100644
--- a/src/corelib/tools/qcollator_win.cpp
+++ b/src/corelib/tools/qcollator_win.cpp
@@ -72,6 +72,8 @@ void QCollatorPrivate::init()
if (caseSensitivity == Qt::CaseInsensitive)
collator |= NORM_IGNORECASE;
+ // WINE does not support SORT_DIGITSASNUMBERS :-(
+ // (and its std::sort() crashes on bad comparisons, QTBUG-74209)
if (numericMode)
collator |= SORT_DIGITSASNUMBERS;
@@ -98,16 +100,36 @@ int QCollator::compare(QStringView s1, QStringView s2) const
// runtime convention of comparing strings, the value 2 can be subtracted
// from a nonzero return value. Then, the meaning of <0, ==0, and >0 is
// consistent with the C runtime.
+ // [...] The function returns 0 if it does not succeed.
+ // https://docs.microsoft.com/en-us/windows/desktop/api/stringapiset/nf-stringapiset-comparestringex#return-value
#ifndef USE_COMPARESTRINGEX
- return CompareString(d->localeID, d->collator,
- reinterpret_cast<const wchar_t*>(s1.data()), s1.size(),
- reinterpret_cast<const wchar_t*>(s2.data()), s2.size()) - 2;
+ const int ret = CompareString(d->localeID, d->collator,
+ reinterpret_cast<const wchar_t *>(s1.data()), s1.size(),
+ reinterpret_cast<const wchar_t *>(s2.data()), s2.size());
#else
- return CompareStringEx(LPCWSTR(d->localeName.utf16()), d->collator,
- reinterpret_cast<LPCWSTR>(s1.data()), s1.size(),
- reinterpret_cast<LPCWSTR>(s2.data()), s2.size(), NULL, NULL, 0) - 2;
+ const int ret = CompareStringEx(LPCWSTR(d->localeName.utf16()), d->collator,
+ reinterpret_cast<LPCWSTR>(s1.data()), s1.size(),
+ reinterpret_cast<LPCWSTR>(s2.data()), s2.size(),
+ nullptr, nullptr, 0);
#endif
+ if (Q_LIKELY(ret))
+ return ret - 2;
+
+ switch (DWORD error = GetLastError()) {
+ case ERROR_INVALID_FLAGS:
+ qWarning("Unsupported flags (%d) used in QCollator", int(d->collator));
+ break;
+ case ERROR_INVALID_PARAMETER:
+ qWarning("Invalid parameter for QCollator::compare()");
+ break;
+ default:
+ qWarning("Failed (%ld) comparison in QCollator::compare()", long(error));
+ break;
+ }
+ // We have no idea what to return, so pretend we think they're equal.
+ // At least that way we'll be consistent if we get the same values swapped ...
+ return 0;
}
QCollatorSortKey QCollator::sortKey(const QString &string) const
diff --git a/src/corelib/tools/qscopeguard.qdoc b/src/corelib/tools/qscopeguard.qdoc
index 70e13ab2fd..21b0bab9cf 100644
--- a/src/corelib/tools/qscopeguard.qdoc
+++ b/src/corelib/tools/qscopeguard.qdoc
@@ -33,7 +33,7 @@ QT_BEGIN_NAMESPACE
\class QScopeGuard
\since 5.12
\inmodule QtCore
- \brief Provides a scope guard for calling a function at the of
+ \brief Provides a scope guard for calling a function at the end of
a scope.
*/
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index da010eca0c..98cce87464 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -1468,7 +1468,7 @@ const QString::Null QString::null = { };
In all of the QString functions that take \c{const char *}
parameters, the \c{const char *} is interpreted as a classic
C-style '\\0'-terminated string encoded in UTF-8. It is legal for
- the \c{const char *} parameter to be 0.
+ the \c{const char *} parameter to be \nullptr.
You can also provide string data as an array of \l{QChar}s:
@@ -2041,7 +2041,7 @@ const QString::Null QString::null = { };
the size of wchar. If wchar is 4 bytes, the \a string is interpreted as UCS-4,
if wchar is 2 bytes it is interpreted as UTF-16.
- If \a size is -1 (default), the \a string has to be 0 terminated.
+ If \a size is -1 (default), the \a string has to be \\0'-terminated.
\sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdWString()
*/
@@ -2107,7 +2107,7 @@ int QString::toUcs4_helper(const ushort *uc, int length, uint *out)
If \a unicode is 0, a null string is constructed.
- If \a size is negative, \a unicode is assumed to point to a nul-terminated
+ If \a size is negative, \a unicode is assumed to point to a \\0'-terminated
array and its length is determined dynamically. The terminating
nul-character is not considered part of the string.
@@ -5448,7 +5448,7 @@ static QVector<uint> qt_convert_to_ucs4(QStringView string);
this string is replaced by the Unicode's replacement character
(QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}).
- The returned vector is not NUL terminated.
+ The returned vector is not \\0'-terminated.
\sa fromUtf8(), toUtf8(), toLatin1(), toLocal8Bit(), QTextCodec, fromUcs4(), toWCharArray()
*/
@@ -5480,7 +5480,7 @@ static QVector<uint> qt_convert_to_ucs4(QStringView string)
this string is replaced by the Unicode's replacement character
(QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}).
- The returned vector is not NUL terminated.
+ The returned vector is not \\0'-terminated.
\sa QString::toUcs4(), QStringView::toUcs4(), QtPrivate::convertToLatin1(),
QtPrivate::convertToLocal8Bit(), QtPrivate::convertToUtf8()
@@ -5638,8 +5638,7 @@ QString QString::fromUtf8_helper(const char *str, int size)
Returns a QString initialized with the first \a size characters
of the Unicode string \a unicode (ISO-10646-UTF-16 encoded).
- If \a size is -1 (default), \a unicode must be terminated
- with a 0.
+ If \a size is -1 (default), \a unicode must be \\0'-terminated.
This function checks for a Byte Order Mark (BOM). If it is missing,
host byte order is assumed.
@@ -5670,8 +5669,7 @@ QString QString::fromUtf16(const ushort *unicode, int size)
Returns a QString initialized with the first \a size characters
of the Unicode string \a str (ISO-10646-UTF-16 encoded).
- If \a size is -1 (default), \a str must be terminated
- with a 0.
+ If \a size is -1 (default), \a str must be \\0'-terminated.
This function checks for a Byte Order Mark (BOM). If it is missing,
host byte order is assumed.
@@ -5691,8 +5689,7 @@ QString QString::fromUtf16(const ushort *unicode, int size)
Returns a QString initialized with the first \a size characters
of the Unicode string \a str (ISO-10646-UCS-4 encoded).
- If \a size is -1 (default), \a str must be terminated
- with a 0.
+ If \a size is -1 (default), \a str must be \\0'-terminated.
\sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String()
*/
@@ -5703,8 +5700,7 @@ QString QString::fromUtf16(const ushort *unicode, int size)
Returns a QString initialized with the first \a size characters
of the Unicode string \a unicode (ISO-10646-UCS-4 encoded).
- If \a size is -1 (default), \a unicode must be terminated
- with a 0.
+ If \a size is -1 (default), \a unicode must be \\0'-terminated.
\sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String()
*/
@@ -10358,7 +10354,7 @@ ownership of it, no memory is freed when instances are destroyed.
Returns a Unicode representation of the string reference. Since
the data stems directly from the referenced string, it is not
- null-terminated unless the string reference includes the string's
+ \\0'-terminated unless the string reference includes the string's
null terminator.
\sa string()
@@ -11900,7 +11896,7 @@ QByteArray QStringRef::toUtf8() const
this string is replaced by the Unicode's replacement character
(QChar::ReplacementCharacter, which corresponds to \c{U+FFFD}).
- The returned vector is not NUL terminated.
+ The returned vector is not \\0'-terminated.
\sa toUtf8(), toLatin1(), toLocal8Bit(), QTextCodec
*/