Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::wcsxfrm

      From cppreference.com
      <cpp‎ |string‎ |wide
       
       
       
       
      Defined in header<cwchar>
      std::size_t wcsxfrm(wchar_t* dest,constwchar_t* src,std::size_t count);

      Transforms the null-terminated wide string pointed to bysrc into the implementation-defined form such that comparing two transformed strings withstd::wcscmp gives the same result as comparing the original strings withstd::wcscoll, 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+ std::wcsxfrm(nullptr, 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 usestd::wcsxfrm to transform all the strings just once, and subsequently compare the transformed wide strings withstd::wcscmp.

      [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 <cwchar>#include <iostream> int main(){std::setlocale(LC_ALL,"sv_SE.utf8"); std::wstring in1= L"\u00e5r";std::wstring out1(1+ std::wcsxfrm(nullptr, in1.c_str(),0), L' ');std::wstring in2= L"\u00e4ngel";std::wstring out2(1+ std::wcsxfrm(nullptr, in2.c_str(),0), L' ');     std::wcsxfrm(&out1[0], in1.c_str(), out1.size());    std::wcsxfrm(&out2[0], in2.c_str(), out2.size()); std::wcout<<"In the Swedish locale: ";if(out1< out2)std::wcout<< in1<<" before "<< in2<<'\n';elsestd::wcout<< in2<<" before "<< in1<<'\n'; std::wcout<<"In lexicographical comparison: ";if(in1< in2)std::wcout<< in1<<" before "<< in2<<'\n';elsestd::wcout<< in2<<" before "<< in1<<'\n'; }

      Output:

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

      [edit]See also

      transform a string so thatstrcmp would produce the same result asstrcoll
      (function)[edit]
      [virtual]
      transforms a string so that collation can be replaced by comparison
      (virtual protected member function ofstd::collate<CharT>)[edit]
      compares two wide strings in accordance to the current locale
      (function)[edit]
      C documentation forwcsxfrm
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/wide/wcsxfrm&oldid=153124"

      [8]ページ先頭

      ©2009-2025 Movatter.jp