wcscoll
|
ヘッダーで定義
<wchar.h>
|
||
|
int
wcscoll
(
const
wchar_t
*
lhs,
const
wchar_t
*
rhs
)
;
|
(C95以降) | |
現在インストールされているロケールの LC_COLLATE カテゴリで定義された照合順序に従って、2つのヌル終端ワイド文字列を比較します。
目次 |
パラメータ
| lhs, rhs | - | 比較対象のヌル終端ワイド文字列へのポインタ |
戻り値
lhs
が
rhs
より
小さい
(先行する)場合は負の値。
0
lhs
が
rhs
に
等しい
場合。
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