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

Add Qt::SplitBehavior argument to QStringList::join() methods

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • None

    Description

      Make a symmetric method to QString::split(), taking Qt::SplitBehavior as an additional argument. QString::split() offers to behave according to passed Qt::SplitBehavior argument - the same would make perfect sense for QStringList::join().

      Use case (many places in Creator):

      There is a need to join multiple error messages with '\n' separator. But sometimes returned error messages are empty strings. When forming the final error message it could be very handy to use join method. Unfortunately, when there are empty strings, they are not being filtered out, so, as a result, we may form a final error with unneeded line ends, e.g.:

      void errorMessage()
      {
          const QString error1 = ...; // empty
          const QString error2 = ...; // has content
          const QStringList errors = {error1, error2};
          return errors.join('\n'); // result is "\n[error2]", while desired behaviour is "[error2]"
      }
      

      Having a possibility to do:

          return errors.join('\n', Qt::SkipEmptyParts);
      

      would be very handful.

      Most probably the same could be done for QByteArrayList::join() method. Side note: it looks like QByteArray::split() is lacking Qt::SplitBehavior argument for API completeness.

      In the end - not sure if the "SplitBehavior" name itself is the best in context of joining strings (as it was fine in context of splitting string). However, still the values themselves {Qt::KeepEmptyParts, Qt::SkipEmptyParts} are fine with context of joining.

      Attachments

        For Gerrit Dashboard: QTBUG-110900
        # Subject Branch Project Status CR V

        Activity

          People

            mmutz Marc Mutz
            jkobus Jarek Kobus
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change