Important: Please read the Qt Code of Conduct -

QCollator doesn't sort in DUCET/CLDR order

  • Good day all,

    I'm attempting to use QCollator to generate and index in the standard DUCET/CDLR order, as given in collation chart, but am having no luck, certain characters (eg overline and $) are resolutely sorted incorrectly.

    Here's a tiny bit of test code:

         QCollator collator;
         collator.setLocale(QLocale("en_GB")); // what are the values for collation strategy keys?
         QVector<QString> v = {" space [whitespace]", "$ dollar [currency]", "% percent [punctuation]", "2 two [digit]", "1 one [digit]", "‾ overline [punctuation]", "+ plus [symbol]", "< less than [symbol]","# hash [punctuation]"};
         std::sort(v.begin(), v.end(), collator);
         qDebug() << v;

    This produces the following output:

     QVector(" space [whitespace]", "# hash [punctuation]", "$ dollar [currency]", "% percent [punctuation]", "? overline [punctuation]", "+ plus [symbol]", "< less than [symbol]", "1 one [digit]", "2 two [digit]")

    but I'm expecting (hoping for) this order:

    QVector(" space [whitespace]", "? overline [punctuation]", "# hash [punctuation]", "% percent [punctuation]", "+ plus [symbol]", "< less than [symbol]", "$ dollar [currency]", "1 one [digit]", "2 two [digit]")

    i.e. I'm expecting the ordering specified here:

    So the overline character should be the first of the set of punctuation characters
    and the $ character should appear after the [symbols] ... ?

    Any idea what I'm doing wrong?

    Many thanks!

Log in to reply