名前空間
変種
操作

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

From cppreference.com
< cpp‎ | locale‎ | collate
 
 
 
 
 
ヘッダー <locale> で定義
public:
string_type transform( const CharT* low, const CharT* high ) const;
(1)
protected:
virtual do_transform( const CharT* low, const CharT* high ) const;
(2)
1) 公開メンバ関数。最も派生したクラスのprotected仮想メンバ関数do_transformを呼び出します。
2) 文字シーケンス[lowhigh)を、他の文字列に対するtransform()の呼び出し結果と比較して辞書式順序(例: 文字列に対するoperator<)で比較した場合に、同じ2つの文字列に対するdo_compare()の呼び出しと同じ結果を生じるような文字列に変換します。

目次

[編集] パラメータ

low - 変換するシーケンスの最初の文字へのポインタ
high - 変換するシーケンスの終端の次のポインタ

[編集] 戻り値

変換された文字列。この変換により、元の文字列の照合の代わりに、変換された文字列の辞書式順序比較を使用できるようになります。「C」ロケールでは、返される文字列は[lowhigh)の正確なコピーです。他のロケールでは、返される文字列の内容は実装定義であり、サイズはかなり長くなる可能性があります。

[編集] 注記

照合での使用に加えて、変換された文字列の実装定義の形式は、std::regex_traits<>::transform_primaryにも認識されており、これにより同値クラス情報を抽出できます。

[編集]

#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';
    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

[編集] 関連項目

strcmpstrcoll と同じ結果を生成するように文字列を変換する
(関数) [編集]
wcscmpwcscollと同じ結果を生成するようにワイド文字列を変換する
(関数) [編集]
English 日本語 中文(简体) 中文(繁體)