summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qbytearray.cpp6
-rw-r--r--tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp27
2 files changed, 31 insertions, 2 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 52af67c86a..d57eeaf188 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -2697,8 +2697,9 @@ QByteArray QByteArray::toLower() const
{
QByteArray s(*this);
uchar *p = reinterpret_cast<uchar *>(s.data());
+ uchar *e = reinterpret_cast<uchar *>(s.end());
if (p) {
- while (*p) {
+ while (p != e) {
*p = QChar::toLower((ushort)*p);
p++;
}
@@ -2720,8 +2721,9 @@ QByteArray QByteArray::toUpper() const
{
QByteArray s(*this);
uchar *p = reinterpret_cast<uchar *>(s.data());
+ uchar *e = reinterpret_cast<uchar *>(s.end());
if (p) {
- while (*p) {
+ while (p != e) {
*p = QChar::toUpper((ushort)*p);
p++;
}
diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
index 8fac232962..52e1850c87 100644
--- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
@@ -151,6 +151,8 @@ private slots:
#if defined(Q_COMPILER_LAMBDA)
void literals();
#endif
+ void toUpperLower_data();
+ void toUpperLower();
void macTypes();
@@ -1999,6 +2001,31 @@ void tst_QByteArray::literals()
}
#endif
+void tst_QByteArray::toUpperLower_data()
+{
+ QTest::addColumn<QByteArray>("input");
+ QTest::addColumn<QByteArray>("upper");
+ QTest::addColumn<QByteArray>("lower");
+
+ QTest::newRow("empty") << QByteArray() << QByteArray() << QByteArray();
+ QTest::newRow("ascii") << QByteArray("Hello World, this is a STRING")
+ << QByteArray("HELLO WORLD, THIS IS A STRING")
+ << QByteArray("hello world, this is a string");
+ QTest::newRow("latin1") << QByteArray("R\311sum\351")
+ << QByteArray("R\311SUM\311")
+ << QByteArray("r\351sum\351");
+ QTest::newRow("nul") << QByteArray("a\0B", 3) << QByteArray("A\0B", 3) << QByteArray("a\0b", 3);
+}
+
+void tst_QByteArray::toUpperLower()
+{
+ QFETCH(QByteArray, input);
+ QFETCH(QByteArray, upper);
+ QFETCH(QByteArray, lower);
+ QCOMPARE(input.toUpper(), upper);
+ QCOMPARE(input.toLower(), lower);
+}
+
void tst_QByteArray::macTypes()
{
#ifndef Q_OS_MAC