summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/text/qstring.cpp')
-rw-r--r--src/corelib/text/qstring.cpp64
1 files changed, 36 insertions, 28 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 6095551738..72de9adf17 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -1,14 +1,13 @@
/****************************************************************************
**
-** Copyright (C) 2021 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Copyright (C) 2018 Intel Corporation.
** Copyright (C) 2019 Mail.ru Group.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:COMM$
-**
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
@@ -17,25 +16,26 @@
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
-** $QT_END_LICENSE$
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
-**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
+** $QT_END_LICENSE$
**
****************************************************************************/
@@ -647,6 +647,8 @@ void qt_from_latin1(ushort *dst, const char *str, size_t size) noexcept
# endif
#endif
#if defined(__mips_dsp)
+ static_assert(sizeof(qsizetype) == sizeof(int),
+ "oops, the assembler implementation needs to be called in a loop");
if (size > 20)
qt_fromlatin1_mips_asm_unroll8(dst, str, size);
else
@@ -802,6 +804,8 @@ static void qt_to_latin1_internal(uchar *dst, const ushort *src, qsizetype lengt
}
#endif
#if defined(__mips_dsp)
+ static_assert(sizeof(qsizetype) == sizeof(int),
+ "oops, the assembler implementation needs to be called in a loop");
qt_toLatin1_mips_dsp_asm(dst, src, length);
#else
while (length--) {
@@ -4562,13 +4566,13 @@ int QString::lastIndexOf(const QRegularExpression &re, int from, QRegularExpress
return -1;
}
- int endpos = (from < 0) ? (size() + from + 1) : (from);
+ int endpos = (from < 0) ? (size() + from + 1) : (from + 1);
QRegularExpressionMatchIterator iterator = re.globalMatch(*this);
int lastIndex = -1;
while (iterator.hasNext()) {
QRegularExpressionMatch match = iterator.next();
int start = match.capturedStart();
- if (start <= endpos) {
+ if (start < endpos) {
lastIndex = start;
if (rmatch)
*rmatch = std::move(match);
@@ -7184,13 +7188,17 @@ QString QString::vasprintf(const char *cformat, va_list ap)
if (length_mod == lm_l) {
const ushort *buff = va_arg(ap, const ushort*);
const ushort *ch = buff;
- while (*ch != 0)
+ while (precision != 0 && *ch != 0) {
++ch;
+ --precision;
+ }
subst.setUtf16(buff, ch - buff);
- } else
+ } else if (precision == -1) {
subst = QString::fromUtf8(va_arg(ap, const char*));
- if (precision != -1)
- subst.truncate(precision);
+ } else {
+ const char *buff = va_arg(ap, const char*);
+ subst = QString::fromUtf8(buff, qstrnlen(buff, precision));
+ }
++c;
break;
}
@@ -8231,7 +8239,7 @@ QVector<QStringRef> QString::splitRef(const QRegularExpression &re, SplitBehavio
\value NormalizationForm_KC Compatibility Decomposition followed by Canonical Composition
\sa normalized(),
- {http://www.unicode.org/reports/tr15/}{Unicode Standard Annex #15}
+ {https://www.unicode.org/reports/tr15/}{Unicode Standard Annex #15}
*/
/*!
@@ -12308,7 +12316,7 @@ static qsizetype qLastIndexOf(Haystack haystack0, qsizetype from,
const auto needle = needle0.data();
const auto *end = haystack;
haystack += from;
- const std::size_t sl_minus_1 = sl - 1;
+ const std::size_t sl_minus_1 = sl ? sl - 1 : 0;
const auto *n = needle + sl_minus_1;
const auto *h = haystack + sl_minus_1;
std::size_t hashNeedle = 0, hashHaystack = 0;