Namespaces
Variants

wcscoll

From cppreference.net
< c ‎ | string ‎ | wide
ヘッダーで定義 <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

参考文献

  • C11標準 (ISO/IEC 9899:2011):
  • 7.29.4.4.2 wcscoll関数 (p: 433-434)
  • C99標準 (ISO/IEC 9899:1999):
  • 7.24.4.4.2 wcscoll関数 (p: 379-380)

関連項目

現在のロケールに従って2つの文字列を比較する
(関数)
(C95)
ワイド文字列を変換し、 wcscmp wcscoll と同じ結果を生成するようにする
(関数)
(C95)
2つのワイド文字列を比較する
(関数)