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

QCollatorSortKey is not working properly without ICU support

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 6.0.0 Beta5
    • Fix Version/s: None
    • Component/s: Core: Locales (i18n)
    • Labels:
      None
    • Platform/s:
      All

      Description

      While extending tst_QCollator to support QCollatorSortKey, I've noticed that on platforms without ICU (!QT_CONFIG(icu)) the result of QCollatorSortKey::compare is not always equal to the results of QCollator::compare.

      Sample code to illustrate the problem

      auto asSign = [](int compared) { 
          return compared < 0 ? -1 : compared > 0 ? 1 : 0;
      };
      
      QString str1("some str");
      QString str2("some other str");
      
      QCollator collator(/*some initialization params*/);
      
      int collatorResult = asSign(collator.compare(str1, str2));
      
      QCollatorSortKey key1 = collator.sortKey(str1);
      QCollatorSortKey key2 = collator.sortKey(str2);
      
      int collatorKeyResult = asSign(key1.compare(key2));
      

      Based on the parameters of collator (case sensitivity, numeric mode, ignore punctuation) the results of the 2 comparisons can be equal or different, which is quite confusing for me.

      A real code for the test can be found in qtbase/tests/auto/corelib/text/qcollator/tst_qcollator.cpp

      Good starting points are qtbase/src/corelib/text/qcollator_macx.cpp (for Mac) and qtbase/src/corelib/text/qcollator_win.cpp (for Windows)

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              cnn Qt Core & Network
              Reporter:
              ivan.solovev Ivan Solovev
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes