This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [libstdc++] Transforming a string to a primary sort key


On Fri, Mar 28, 2014 at 12:40 PM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> That sounds like strxfrm to me - if it's not, could you explain how it
> differs?

wcsxfrm works as expected for above case, but I'm confused: wcsxfrm is
defined as "The transformation shall be such that if wcscmp() is
applied to two transformed wide strings, it shall  return  a value
greater than, equal to, or less than 0, corresponding to the result of
wcscoll() and wcscoll_l() applied to the same two original
wide-character strings, and the same LC_COLLATE category of the
current locale or the locale object locale, respectively."

But in my machine the following code outputs 0:

#include <locale.h>
#include <wchar.h>
#include <stdio.h>
#include <assert.h>
#include <errno.h>

int main()
{
    setlocale(LC_ALL, "en_US.UTF-8");
    wchar_t st1[] = L"AÀÁÂÃÄÅaàáâãäå";
    wchar_t st2[] = L"aaaaaaaaaaaaaa";
    wchar_t buff1[4096];
    wchar_t buff2[4096];
    errno = 0;
    int n1 = wcsxfrm(buff1, st1, wcslen(st1));
    assert(errno == 0);
    int n2 = wcsxfrm(buff2, st2, wcslen(st2));
    assert(errno == 0);
    assert(n1 < 4096);
    assert(n2 < 4096);
    buff1[n1] = L'\0';
    buff2[n2] = L'\0';
    printf("%d\n", wcscmp(buff1, buff2) == wcscoll(st1, st2));
    return 0;
}

Is 0 an expected behavior?

Actually, regex_traits::transform, instead of
regex_traits::transform_primary is exactly a wrapper of strxfrm and
wcsxfrm; shouldn't transfrom_primary mean something different?

Thanks!


-- 
Regards,
Tim Shen


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]