Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      wcsxfrm

      From cppreference.com
      <c‎ |string‎ |wide
       
       
       
      Null-terminated wide strings
       
      Defined in header<wchar.h>
      size_t wcsxfrm(wchar_t* dest,constwchar_t* src,size_t count);
      (until C99)
      (since C95)
      size_t wcsxfrm(wchar_t*restrict dest,constwchar_t*restrict src,size_t count);
      (since C99)

      Transforms the null-terminated wide string pointed to bysrc into the implementation-defined form such that comparing two transformed strings withwcscmp gives the same result as comparing the original strings withwcscoll, in the current C locale.

      The firstcount characters of the transformed string are written to destination, including the terminating null character, and the length of the full transformed string is returned, excluding the terminating null character.

      Ifcount is0, thendest is allowed to be a null pointer.

      Contents

      [edit]Notes

      The correct length of the buffer that can receive the entire transformed string is1+wcsxfrm(NULL, src,0)

      This function is used when making multiple locale-dependent comparisons using the same wide string or set of wide strings, because it is more efficient to usewcsxfrm to transform all the strings just once, and subsequently compare the transformed wide strings withwcscmp.

      [edit]Parameters

      dest - pointer to the first element of a wide null-terminated string to write the transformed string to
      src - pointer to the null-terminated wide character string to transform
      count - maximum number of characters to output

      [edit]Return value

      The length of the transformed wide string, not including the terminating null-character.

      [edit]Example

      Run this code
      #include <stdio.h>#include <wchar.h>#include <locale.h> int main(void){setlocale(LC_ALL,"sv_SE.utf8"); constwchar_t*in1= L"\u00e5r";wchar_t out1[1+wcsxfrm(NULL, in1,0)];    wcsxfrm(out1, in1,sizeof out1/sizeof*out1); constwchar_t*in2= L"\u00e4ngel";wchar_t out2[1+wcsxfrm(NULL, in2,0)];    wcsxfrm(out2, in2,sizeof out2/sizeof*out2); printf("In the Swedish locale: ");if(wcscmp(out1, out2)<0)printf("%ls before %ls\n", in1, in2);elseprintf("%ls before %ls\n", in2, in1); printf("In lexicographical comparison: ");if(wcscmp(in1, in2)<0)printf("%ls before %ls\n", in1, in2);elseprintf("%ls before %ls\n", in2, in1);}

      Output:

      In the Swedish locale: år before ängelIn lexicographical comparison: ängel before år

      [edit]References

      • C11 standard (ISO/IEC 9899:2011):
      • 7.29.4.4.4 The wcsxfrm function (p: 434-435)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.24.4.4.4 The wcsxfrm function (p: 380-381)

      [edit]See also

      compares two strings in accordance to the current locale
      (function)[edit]
      (C95)
      compares two wide strings in accordance to the current locale
      (function)[edit]
      (C95)
      compares two wide strings
      (function)[edit]
      transform a string so that strcmp would produce the same result as strcoll
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/string/wide/wcsxfrm&oldid=87761"

      [8]ページ先頭

      ©2009-2025 Movatter.jp