This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [RFC] collate_members_wchar_t.cc
- From: Nathan Myers <ncm-nospam at cantrip dot org>
- To: libstdc++ at gcc dot gnu dot org
- Date: Sat, 9 Mar 2002 19:31:11 +0000
- Subject: Re: [RFC] collate_members_wchar_t.cc
- References: <3C8A5868.5F82DF90@unitus.it>
On Sat, Mar 09, 2002 at 07:46:00PM +0100, Paolo Carlini wrote:
> if (__cmp > 0)
> return 1;
> else if (__cmp < 0)
> return -1;
> else return 0;
Of course you would have to test it to know which results in
better code, but I would probably have said:
return ((__cmp < 0) ? -1 : (__cmp > 0));
> In the glibc docs I find:
>
> - Function: int wcscmp (const wchar_t *WS1, const wchar_t *WS2)
> The `wcscmp' function compares the wide character string WS1
> against WS2. The value returned is smaller than or larger than
> zero depending on whether the first differing wide character is
> WS1 is smaller or larger than the corresponding character in WS2.
>
> I admit to not fully understand it, that is, I do not understand
> which kind of computation exactly is performed. Moreover, I could not
> find in the docs an explanation of the computation carried out by
> the corresponding wcscoll, which is troubling us. In which ways is
> different?
>
> Without knowing all of this in detail we cannot implement a sensible
> compare for wchar_t.
The difference between .*cmp and .*coll is that the *cmp forms compare
character-by-character, where the *coll forms are allowed to consider
the string as a whole. For example, in French, collation involves
ignoring the accent marks on the first pass, and then sorting by the
reverse order of the presence of accent marks on the vowels. The
naive implementation of collation calls transform (e.g. strxfrm) on
each argument and then applies *cmp to the results.
Nathan Myers
ncm at cantrip dot org