This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [libstdc++] Transforming a string to a primary sort key
- From: Tim Shen <timshen91 at gmail dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>
- Cc: libc-alpha at sourceware dot org, Paolo Carlini <paolo dot carlini at oracle dot com>, roland at gnu dot org
- Date: Fri, 28 Mar 2014 14:23:35 -0400
- Subject: Re: [libstdc++] Transforming a string to a primary sort key
- Authentication-results: sourceware.org; auth=none
- References: <CAPrifDmGAR=wVP7++dDC--V9R0jfO2r7ohvD_Bnnd3YM3VNASQ at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1403281639120 dot 6067 at digraph dot polyomino dot org dot uk>
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