Fix QString(QLatin1String) constructor for substrings

QLatin1String now has a constructor that takes explicit length, which
makes it possible to create a QLatin1String that isn't null-terminated.
Made the QString(QLatin1String) constructor work in that case.

Change-Id: I4f4f07a956144b7ea4aa9c58a61c755fb99ef1b3
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
bb10
Kent Hansen 2012-02-01 20:15:24 +01:00 committed by Qt by Nokia
parent ec9833388f
commit 35b19be478
2 changed files with 10 additions and 1 deletions

View File

@ -685,7 +685,7 @@ private:
typedef QLatin1String QLatin1Literal;
inline QString::QString(const QLatin1String &aLatin1) : d(fromLatin1_helper(aLatin1.latin1()))
inline QString::QString(const QLatin1String &aLatin1) : d(fromLatin1_helper(aLatin1.latin1(), aLatin1.size()))
{ }
inline int QString::length() const
{ return d->size; }

View File

@ -223,6 +223,7 @@ private slots:
void operatorGreaterWithQLatin1String();
void compareQLatin1Strings();
void fromQLatin1StringWithLength();
};
typedef QList<int> IntList;
@ -5277,6 +5278,14 @@ void tst_QString::compareQLatin1Strings()
QVERIFY(!(subab >= subabc));
}
void tst_QString::fromQLatin1StringWithLength()
{
QLatin1String latin1foo("foobar", 3);
QString foo(latin1foo);
QCOMPARE(foo.size(), latin1foo.size());
QCOMPARE(foo, QString::fromLatin1("foo"));
}
QTEST_APPLESS_MAIN(tst_QString)
#include "tst_qstring.moc"