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

Null and empty QString

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • Not Evaluated
    • 5.0.0
    • 4.4.3
    • None

    Description

      (Note: this report is valid for 4.5 snapshots as well)

      The result of the test case in the bottom is:

      Null does contain Blank
      Blank does contain Null

      Null does NOT start with Blank
      Blank does start with Null

      Null does NOT end with Blank
      Blank does end with Null

      If nullstr.contains(blankstr) is true then nullstr.startsWith(blankstr) and nullstr.endsWith(blankstr) should both also be true. Or to phrase it another way; if the contains method is going to treat null strings as equivalent to blank strings then the startsWith and endsWith methods should do that too. The documentation states "All functions except isNull() treat null strings the same as empty strings."

      Test case:

      #include <QtCore>
      
      int main(int argc, char * argv[])
      {
          QCoreApplication app(argc, argv);
      
          QString nullstr;
          QString blankstr("");
          bool r1, r2;
      
          const char *n = "Null", *b = "Blank", *d = "does", *dn = "does NOT",
                     *c = "contain", *s = "start with", *e = "end with";
      
          r1 = nullstr.contains(blankstr);
          r2 = blankstr.contains(nullstr);
          fprintf(stdout, "  %s %s %s %s\n  %s %s %s %s\n\n",
                  n, (r1 ? d : dn), c, b,
                  b, (r2 ? d : dn), c, n);
      
          r1 = nullstr.startsWith(blankstr);
          r2 = blankstr.startsWith(nullstr);
          fprintf(stdout, "  %s %s %s %s\n  %s %s %s %s\n\n",
                  n, (r1 ? d : dn), s, b,
                  b, (r2 ? d : dn), s, n);
      
          r1 = nullstr.endsWith(blankstr);
          r2 = blankstr.endsWith(nullstr);
          fprintf(stdout, "  %s %s %s %s\n  %s %s %s %s\n\n",
                  n, (r1 ? d : dn), e, b,
                  b, (r2 ? d : dn), e, n);
      
          return 0;
      }
      //---------------------------------------------------------------------------
      

      Note: this cannot be changed before Qt 5 because it changes behaviour.

      Attachments

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

        Activity

          People

            stormols Marius Storm-Olsen
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes