std::wcscoll
提供: cppreference.com
ヘッダ <cwchar> で定義
|
||
int wcscoll( const wchar_t* lhs, const wchar_t* rhs ); |
||
LC_COLLATE カテゴリで定義された、 std::setlocale で最も最近設定されたロケールに従って、2つのヌル終端ワイド文字列を比較します。
目次 |
[編集] 引数
lhs, rhs | - | 比較するヌル終端ワイド文字列を指すポインタ |
[編集] 戻り値
lhs
が rhs
より小さい (前に来る) 場合は負の値。
lhs
が rhs
と等しい場合は 0。
lhs
が rhs
より大きい (後に来る) 場合は正の値。
[編集] ノート
照合順序は辞書順です。 アルファベットの文字 (等価クラス) の位置は大文字小文字や変種よりも高い優先度を持ちます。 等価クラス内では、小文字は同等な大文字よりも前に照合され、ダイアクリティカルマーク付きの文字にはロケール固有の順序が適用されるかもしれません。 ロケールによっては、文字のグループが単一の照合単位として比較されます。 例えば、チェコ語の "ch" は "h" より後、 "i" より前に、ハンガリー語の "dzs" は "dz" より後、 "g" より前に来ます。
[編集] 例
Run this code
#include <iostream> #include <clocale> void try_compare(const wchar_t* p1, const wchar_t* p2) { if(std::wcscoll(p1, p2) < 0) std::wcout << p1 << " before " << p2 << '\n'; else std::wcout << p2 << " before " << p1 << '\n'; } int main() { std::setlocale(LC_ALL, "en_US.utf8"); std::wcout << "In the American locale: "; try_compare(L"hrnec", L"chrt"); std::setlocale(LC_COLLATE, "cs_CZ.utf8"); std::wcout << "In the Czech locale: "; try_compare(L"hrnec", L"chrt"); std::setlocale(LC_COLLATE, "en_US.utf8"); std::wcout << "In the American locale: "; try_compare(L"år", L"ängel"); std::setlocale(LC_COLLATE, "sv_SE.utf8"); std::wcout << "In the Swedish locale: "; try_compare(L"år", L"ängel"); }
出力:
In the American locale: chrt before hrnec In the Czech locale: hrnec before chrt In the American locale: ängel before år In the Swedish locale: år before ängel
[編集] 関連項目
現在のロケールに従って2つの文字列を比較します (関数) | |
[仮想] |
このファセットの照合ルールを用いて2つの文字列を比較します ( std::collate<CharT> の仮想プロテクテッドメンバ関数)
|
wcscoll と同じ結果を wcscmp で得られるようにワイド文字列を変換します (関数) | |
wcscoll の C言語リファレンス
|