PDA

View Full Version : Khmer language words sorting



yazwas
26th August 2011, 12:45
Good day

I'm trying to sort a list of Khmer words, but so far I'm not successful. I'm using UTF-8 and qSort to do the job, but there is something wrong, or something missing.
(the below code worked ok for English and French)


bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
{
return s1.trimmed().toLower() < s2.trimmed().toLower();
}

void mySort(QStringList &list)
{
qDebug() << "unsorted list: " << list;
qSort(list.begin(), list.end(), caseInsensitiveLessThan);
qDebug() << " sorted list: " << list;
}


This is an example list I have that is sorted, and should not be resorted when using the sort code.

ក1, ក៏2, កក3, កក់4, កករ5, កកាត6, កកាយ7, áž€áž€áž·áž…áž€áž€áž»á …8, កកិត9, កកិល10

but when using my sorting code (above), I'm getting this list.

ក1, កក3, កករ5, កកាត6, កកាយ7, áž€áž€áž·áž…áž€áž€áž»á …8, កកិត9, កកិល10, កក់4, ក៏2

Any suggestions are most welcomed?

Thank you

Rachol
26th August 2011, 13:16
From documentation of QString:


bool QString::operator< ( const QString & other ) const
Returns true if this string is lexically less than string other; otherwise returns false.
The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the QString::localeAwareCompare() function.