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

Documentation for QTextBoundaryFinder::position()

    XMLWordPrintable

Details

    • Linux/X11

    Description

      The documentation here: https://doc.qt.io/qt-5/qtextboundaryfinder.html#position

      ...says: "The range is from 0 (the beginning of the string) to the length of the string inclusive."

      After move past the last grapheme boundary, position() will always return -1.

      See code here:

      int QTextBoundaryFinder::toNextBoundary()
      {
          if (!d || pos < 0 || pos >= length) {
              pos = -1;
              return pos;
          }
      ...
      

      Method toPreviousBoundary() has similar code.

      Here are two possible solutions:

      1) Update the docs.  Maybe there is interesting history behind this design decision to be shared. 

      2) Change the code. Do not update pos; only return -1.
      Ex: if (!d || pos < 0 || pos >= length) return -1;

      Simple repro:

      #include <QTextBoundaryFinder>
      
      int main(int argc, char *argv[])
      {
          const QLatin1String lstr{"abc"};
          const QString str{lstr};
          QTextBoundaryFinder f{QTextBoundaryFinder::BoundaryType::Grapheme, str};
          const int p1 = f.position(); // 0
          const int b1 = f.toNextBoundary(); // 1
          const int p2 = f.position(); // 1
          const int b2 = f.toNextBoundary(); // 2
          const int p3 = f.position(); // 2
          const int b3 = f.toNextBoundary(); // 3
          const int p4 = f.position(); // 3
          const int b4 = f.toNextBoundary(); // -1
          const int p5 = f.position(); // -1
          const int b5 = f.toNextBoundary(); // -1
          const int p6 = f.position(); // -1
          const int b6 = f.toPreviousBoundary(); // -1
          const int p7 = f.position(); // -1
          const int b7 = f.toPreviousBoundary(); // -1
          const int p8 = f.position(); // -1
          const int b8 = f.toPreviousBoundary(); // -1
          const int p9 = f.position(); // -1
          // @DebugBreakpoint
          int dummy = 1;
      }
      

       

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            kevinarpe@gmail.com Kevin Connor ARPE
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes