Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
4.4.3
-
None
Description
By default, QString::section() return the trailing delimiter of the string.
QString str("a,b,c,"); str.section(',',2); // should return c, not c,
The delimiter should only be included with the flag QString::SectionIncludeTrailingSep.
QString str("a,b,c,"); str.section(',',2, QString::SectionIncludeTrailingSep); // should "c,"
This was also the behavior of Qt 3.
Here is a test case for this behavior:
@@ -3463,6 +3463,14 @@ void tst_QString::section_data() << QString("\\b") << 3 << 3 << int(QString::SectionDefault) << QString("is") << true; + QTest::newRow( "task247096-trailing separator" ) << QString("a,b,c,") + << QString(",") << 2 << -1 + << int(QString::SectionDefault) + << QString("c") << false; + QTest::newRow( "task247096-trailing separator-rx" ) << QString("a,b,c,") + << QString(",") << 2 << -1 + << int(QString::SectionDefault) + << QString("c") << true; + QTest::newRow( "task247096-leading separator" ) << QString(",a,b,c") + << QString(",") << 0 << 0 + << int(QString::SectionDefault) + << QString("a") << false; + QTest::newRow( "task247096-leading separator-rx" ) << QString(",a,b,c") + << QString(",") << 0 << 0 + << int(QString::SectionDefault) + << QString("a") << true; }