Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::collate<CharT>::transform, do_transform

      From cppreference.com
      <cpp‎ |locale‎ |collate
       
       
       
      Localization library
       
       
      Defined in header<locale>
      public:
      string_type transform(const CharT* low,const CharT* high)const;
      (1)
      protected:
      virtual string_type do_transform(const CharT* low,const CharT* high)const;
      (2)
      1) Public member function, calls the protected virtual member functiondo_transform of the most derived class.
      2) Converts the character sequence[lowhigh) to a string that, compared lexicographically (e.g. withoperator< for strings) with the result of callingtransform() on another string, produces the same result as callingdo_compare() on the same two strings.

      Contents

      [edit]Parameters

      low - pointer to the first character in the sequence to transform
      high - one past the end pointer for the sequence to transform

      [edit]Return value

      The string transformed so that lexicographic comparison of the transformed strings may be used instead of collating of the originals. In the "C" locale, the returned string is the exact copy of[lowhigh). In other locales, the contents of the returned string are implementation-defined, and the size may be considerably longer.

      [edit]Notes

      In addition to the use in collation, the implementation-specific format of the transformed string is known tostd::regex_traits<>::transform_primary, which is able to extract the equivalence class information.

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <locale> int main(){std::locale::global(std::locale("sv_SE.utf8"));auto& f=std::use_facet<std::collate<wchar_t>>(std::locale()); std::wstring in1= L"\u00e4ngel";std::wstring in2= L"\u00e5r"; std::wstring out1= f.transform(&in1[0],&in1[0]+ in1.size());std::wstring out2= f.transform(&in2[0],&in2[0]+ in2.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 lexicographic comparison: ";if(in1< in2)std::wcout<< in1<<" before "<< in2<<'\n';elsestd::wcout<< in2<<" before "<< in1<<'\n';}

      Output:

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

      [edit]See also

      transform a string so thatstrcmp would produce the same result asstrcoll
      (function)[edit]
      transform a wide string so thatwcscmp would produce the same result aswcscoll
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/collate/transform&oldid=160061"

      [8]ページ先頭

      ©2009-2025 Movatter.jp