std::collate<CharT>::transform, do_transform
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <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 メンバ関数。 最も派生したクラスの protected virtual メンバ関数
do_transform を呼びます。2) 別の文字列に
transform() を呼んだ結果と辞書的に (例えば文字列に対する operator< で) 比較したときに同じ2つの文字列に do_compare() を呼んだのと同じ結果を生成する文字列に、文字シーケンス [low, high) を変換します。引数
| low | - | 変換するシーケンスの最初の文字へのポインタ |
| high | - | 変換するシーケンスの最後の次へのポインタ |
戻り値
元の文字列の照合の代わりに変換後の文字列の辞書的な比較を使用できるような変換後の文字列。 "C" ロケールでは、返される文字列は [low, high) の正確なコピーです。 他のロケールでは、返される文字列の内容は処理系定義であり、そのサイズは相当長くなる可能性もあります。
ノート
照合での使用に加えて、変換後の文字列の処理系固有の書式は等価クラスの情報を抽出することができる std::regex_traits<>::transform_primary にも知られています。
例
Run this code
#include <iostream>
#include <iomanip>
#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';
else
std::wcout << in2 << " before " << in1 << '\n';
std::wcout << "In lexicographic comparison: ";
if(in1 < in2)
std::wcout << in1 << " before " << in2 << '\n';
else
std::wcout << in2 << " before " << in1 << '\n';
}
出力:
In the Swedish locale: år before ängel
In lexicographic comparison: ängel before år
関連項目
| strcoll と同じ結果を strcmp で得られるように文字列を変換します (関数) | |
| wcscoll と同じ結果を wcscmp で得られるようにワイド文字列を変換します (関数) |