From 601d68584921a47d83d833228f5ec698e13b624c Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 23 Jan 2012 12:02:36 +0000 Subject: Make mid() and midRef() properly return empty, non-null objects If we request a substring starting at the very end of the string, QString::mid should return an empty string, not a null string. For instance, QString("abc").mid(3, 0) used to return a null one, while this patch makes it return an empty one. The same thing applies to QString::midRef() and QByteArray::mid(). Change-Id: Ie9efd7a0622d429efd0fb682c19856c19e9469af Reviewed-by: Lars Knoll --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/auto/corelib/tools') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index eda34b0d99..b9951c1b5d 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -1417,6 +1417,10 @@ void tst_QString::mid() QCOMPARE(a.mid(3,3),(QString)"DEF"); QCOMPARE(a.mid(0,0),(QString)""); + QVERIFY(!a.mid(15,0).isNull()); + QVERIFY(a.mid(15,0).isEmpty()); + QVERIFY(!a.mid(15,1).isNull()); + QVERIFY(a.mid(15,1).isEmpty()); QVERIFY(a.mid(9999).isNull()); QVERIFY(a.mid(9999,1).isNull()); @@ -1439,6 +1443,10 @@ void tst_QString::midRef() QCOMPARE(a.midRef(3,3).toString(),(QString)"DEF"); QCOMPARE(a.midRef(0,0).toString(),(QString)""); + QVERIFY(!a.midRef(15,0).toString().isNull()); + QVERIFY(a.midRef(15,0).toString().isEmpty()); + QVERIFY(!a.midRef(15,1).toString().isNull()); + QVERIFY(a.midRef(15,1).toString().isEmpty()); QVERIFY(a.midRef(9999).toString().isEmpty()); QVERIFY(a.midRef(9999,1).toString().isEmpty()); -- cgit v1.2.3