Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3699

QString::section returns a trailing delimiter when asked for last section

    XMLWordPrintable

Details

    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;
      
       }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            poulain Benjamin Poulain (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes