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

QCollatorSortKey is not working properly without ICU support

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.0.0 Beta5
    • Core: Locales (i18n)
    • None
    • All

      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)

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

            thiago Thiago Macieira
            ivan.solovev Ivan Solovev
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: