wcscoll
From cppreference.com
| ヘッダー <wchar.h> で定義 |
||
| int wcscoll( const wchar_t *lhs, const wchar_t *rhs ); |
(C95 以降) | |
現在インストールされているロケールの LC_COLLATE カテゴリによって定義される照合順序に従って、ヌル終端のワイド文字列を比較します。
目次 |
[編集] パラメータ
| lhs, rhs | - | 比較するヌル終端ワイド文字列へのポインタ |
[編集] 戻り値
lhs が rhs より小さい(先行する)場合は負の値。
lhs が rhs と等しい場合は 0。
lhs が rhs より大きい(後続する)場合は正の値。
[編集] 注記
照合順序は辞書順です。つまり、文字のアルファベットにおける位置(その同等クラス)は、大文字/小文字やバリアントよりも優先されます。同等クラス内では、小文字はそれに対応する大文字よりも前に照合され、アクセント記号付きの文字にはロケール固有の順序が適用される場合があります。一部のロケールでは、文字のグループが単一の照合単位として比較されます。たとえば、チェコ語の "ch" は "h" の後に、"i" の前に来ます。ハンガリー語の "dzs" は "dz" の後に、"g" の前に来ます。
[編集] 例
このコードを実行
#include <stdio.h> #include <wchar.h> #include <locale.h> void try_compare(const wchar_t* p1, const wchar_t* p2) { if(wcscoll(p1, p2) < 0) printf("%ls before %ls\n", p1, p2); else printf("%ls before %ls\n", p2, p1); } int main(void) { setlocale(LC_ALL, "en_US.utf8"); printf("In the American locale: "); try_compare(L"hrnec", L"chrt"); setlocale(LC_COLLATE, "cs_CZ.utf8"); printf("In the Czech locale: "); try_compare(L"hrnec", L"chrt"); setlocale(LC_COLLATE, "en_US.utf8"); printf("In the American locale: "); try_compare(L"år", L"ängel"); setlocale(LC_COLLATE, "sv_SE.utf8"); printf("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