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

QCollator can't sort according to "C" and "POSIX" locale definitions when Qt is compiled with ICU

    XMLWordPrintable

Details

    • ab448f731ecd8437c7c5c8b96a0e7f419ec3a7ca (qt/qtbase/5.12) 235ac95520a0fc2c822dedce7358e3c64a764255 (qt/qtbase/dev)

    Description

      Qt is compiled with ICU:

      $ readelf -d /usr/lib/libQt5Core.so.5.8.0 | grep NEEDED | grep icu
       0x0000000000000001 (NEEDED)             Shared library: [libicui18n.so.58]
       0x0000000000000001 (NEEDED)             Shared library: [libicuuc.so.58]
       0x0000000000000001 (NEEDED)             Shared library: [libicudata.so.58]
      

      Example code:

      qcollatortest.cpp
      #include <QCoreApplication>
      #include <QDebug>
      #include <QString>
      #include <QCollator>
      #include <QStringList>
      #include <algorithm>
      #include <locale>
      
      int main(int argc, char** argv)
      {
      	QCoreApplication app(argc, argv);
      
      	QStringList src;
      	src << QLatin1String("Aaa");
      	src << QLatin1String("AAa");
      	src << QLatin1String("aba");
      	src << QLatin1String("Bbb");
      	src << QLatin1String("bab");
      
      	QCollator collator;
      
      	std::sort(src.begin(), src.end(), collator);
      	qDebug() << "qcollator default :" << src;
      
      	collator.setCaseSensitivity(Qt::CaseSensitive);
      	std::sort(src.begin(), src.end(), collator);
      	qDebug() << "qcollator force cs:" << src;
      
      	collator.setCaseSensitivity(Qt::CaseInsensitive);
      	std::sort(src.begin(), src.end(), collator);
      	qDebug() << "qcollator force ci:" << src;
      
      	struct Compare {
      		bool operator()(const QString& left, const QString& right) {
      			return std::locale("")(left.toStdString(), right.toStdString());
      		}
      	};
      
      	std::sort(src.begin(), src.end(), Compare());;
      	qDebug() << "std::locale       :" << src;
      
          return 0;
      }
      

      results:

      $ LC_COLLATE="C" ./qcollatortest 
      qcollator default : ("Aaa", "AAa", "aba", "bab", "Bbb")
      qcollator force cs: ("Aaa", "AAa", "aba", "bab", "Bbb")
      qcollator force ci: ("Aaa", "AAa", "aba", "bab", "Bbb")
      std::locale       : ("AAa", "Aaa", "Bbb", "aba", "bab")
      
      $ LC_COLLATE="en_US.UTF-8" ./qcollatortest 
      qcollator default : ("Aaa", "AAa", "aba", "bab", "Bbb")
      qcollator force cs: ("Aaa", "AAa", "aba", "bab", "Bbb")
      qcollator force ci: ("Aaa", "AAa", "aba", "bab", "Bbb")
      std::locale       : ("Aaa", "AAa", "aba", "bab", "Bbb")
      

      Attachments

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

        Activity

          People

            Eddy Edward Welbourne
            eugeneshalygin Eugene Shalygin
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes