[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: QString::localeAwareCompare() in KDE
From:       Thiago Macieira <thiago () kde ! org>
Date:       2009-05-08 0:58:46
Message-ID: 200905080258.54017.thiago () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


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 = strcoll(toLocal8Bit_helper(data1, length1), 
toLocal8Bit_helper(data2, length2));

    if (delta == 0)
        delta = ucstrcmp(data1, length1, data2, length2);
    return delta;

As you can see, it's basically calling strcoll(3), which is a C library 
function. Setting the default QLocale will have no effect: you have to set 
the C library's locale, via setlocale(3).

In any case, the sorting you find weird is coming from glibc. There's 
little we can do.
-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

["signature.asc" (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic