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

two suggestions aliases for QString: 'rightFrom' and 'between' methods

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • P5: Not important
    • None
    • None
    • None

    Description

      Hi,

      currently there is method

      QString.mid(n);
      

      that returns QString with characters from n-th until last one.

      It might be nice to alias this to:

      QString.rightFrom(n).
      

      It took me a long time to figure out mid can accept only one number, and now I use mid regularly, but I see that code would look much nicer if method had rightFrom name. Mid means in the middle, not on the right side.

      Also, It might be useful to get

      QString.between(n, m)
      

      this method could always take two arguments, and m has to be higher than n.
      this function could return same as QString.mid(n, m-n).

      This two can be lived without, but they could potentially make code look much nicer and easier to read.

      I also use mid(n, m-n) a lot, but in most cases m and n are some really long methods, mostly n is QString.indexof(... , ...), and in most cases I do not create specialized local variable n for it, which makes function mostly like this:

      QString.mid(QString.indexof(ref1, arg1), QString.indexOf(ref2, arg2) - QString.indexof(re1, arg1));
      

      which is long and ugly. It would be (little bit) better and easier to read like this:

      QString.between(QString.indexof(ref1, arg1), QString.indexOf(ref2, arg2));
      

      Regards,
      Petar

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            pperisin Petar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes