wcscoll
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <wchar.h> で定義
|
||
int wcscoll( const wchar_t *lhs, const wchar_t *rhs ); |
(C95以上) | |
現在設定されているロケールの LC_COLLATE カテゴリで定義された照合順序に従って、2つのヌル終端ワイド文字列を比較します。
引数
| lhs, rhs | - | 比較するヌル終端ワイド文字列を指すポインタ |
戻り値
lhs が rhs より小さい (前に来る) 場合は負の値。
lhs が rhs と等しい場合は 0。
lhs が rhs より大きい (後に来る) 場合は正の値。
ノート
照合順序は辞書順です。 アルファベットの文字 (等価クラス) の位置は大文字小文字や変種よりも高い優先度を持ちます。 等価クラス内では、小文字は同等な大文字よりも前に照合され、ダイアクリティカルマーク付きの文字にはロケール固有の順序が適用されるかもしれません。 ロケールによっては、文字のグループが単一の照合単位として比較されます。 例えば、チェコ語の "ch" は "h" より後、 "i" より前に、ハンガリー語の "dzs" は "dz" より後、 "g" より前に来ます。
例
Run this code
#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
参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.29.4.4.2 The wcscoll function (p: 433-434)
- C99 standard (ISO/IEC 9899:1999):
- 7.24.4.4.2 The wcscoll function (p: 379-380)
関連項目
| 現在のロケールに従って2つの文字列を比較します (関数) | |
(C95) |
wcscoll と同じ結果を wcscmp で得られるようにワイド文字列を変換します (関数) |
(C95) |
2つのワイド文字列を比較します (関数) |
wcscoll の C++リファレンス
|