From kde-devel Fri May 08 00:58:46 2009 From: Thiago Macieira Date: Fri, 08 May 2009 00:58:46 +0000 To: kde-devel Subject: Re: QString::localeAwareCompare() in KDE Message-Id: <200905080258.54017.thiago () kde ! org> X-MARC-Message: https://marc.info/?l=kde-devel&m=124174443728045 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============1883483403==" --===============1883483403== Content-type: multipart/signed; boundary=nextPart1373204.xydRKZlZvY; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-transfer-encoding: 7bit --nextPart1373204.xydRKZlZvY Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Peter Penz wrote: >I tracked down the problem to QString::localeAwareCompare(), which is > used in KStringHandler::naturalCompare(). When replacing >QString::localeAwareCompare(a, b) by a.compare(b) the strings above are > sorted correctly, however obviously the capability of locale aware > comparing is lost... > >My guess is that in the context of a KDE application a different locale- >mapping-table is used as when executing the unit test. > >Is somebody familiar with this topic and knows how I can convince the > unit test to run with the same locale settings as a KDE application? I > tried QLocale::setDefault(...) but the unit test always passes > correctly... This is localeAwareCompare for Unix (which aren't Macs): int delta =3D strcoll(toLocal8Bit_helper(data1, length1),=20 toLocal8Bit_helper(data2, length2)); if (delta =3D=3D 0) delta =3D ucstrcmp(data1, length1, data2, length2); return delta; As you can see, it's basically calling strcoll(3), which is a C library=20 function. Setting the default QLocale will have no effect: you have to set= =20 the C library's locale, via setlocale(3). In any case, the sorting you find weird is coming from glibc. There's=20 little we can do. =2D-=20 Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org PGP/GPG: 0x6EF45358; fingerprint: E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358 --nextPart1373204.xydRKZlZvY Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iD8DBQBKA4PHM/XwBW70U1gRAm7AAJ4tECam/fPyhREqz+UMgcbUP0Sc/gCeJnBC a5HoihNU8OHPHULaenZG8so= =rn/6 -----END PGP SIGNATURE----- --nextPart1373204.xydRKZlZvY-- --===============1883483403== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << --===============1883483403==--