Namespaces
Variants

std::ctype<CharT>:: tolower, std::ctype<CharT>:: do_tolower

From cppreference.net
ヘッダーで定義 <locale>
public :
CharT tolower ( CharT c ) const ;
(1)
public :
const CharT * tolower ( CharT * beg, const CharT * end ) const ;
(2)
protected :
virtual CharT do_tolower ( CharT c ) const ;
(3)
protected :
virtual const CharT * do_tolower ( CharT * beg, const CharT * end ) const ;
(4)
1,2) パブリックメンバ関数。最も派生したクラスの保護された仮想メンバ関数 do_tolower を呼び出す。
3) このロケールで小文字形式が定義されている場合、文字 c を小文字に変換します。
4) 文字配列 [ beg , end ) 内の各文字について、小文字形式が存在する場合、その文字を小文字形式で置き換えます。

目次

パラメータ

c - 変換する文字
beg - 変換対象の文字配列の先頭文字へのポインタ
end - 変換対象の文字配列の終端の次を指すポインタ

戻り値

1,3) 小文字の文字、またはこのロケールで小文字形式がリストされていない場合は c
2,4) end

注記

この関数は1:1の文字マッピングのみを実行します。例えば、ギリシャ語の大文字「Σ」には、語中の位置に応じて2つの小文字形式「σ」と「ς」が存在します。この場合、 do_tolower を呼び出しても正しい小文字形式を取得することはできません。

#include <iostream>
#include <locale>
void try_lower(const std::ctype<wchar_t>& f, wchar_t c)
{
    wchar_t up = f.tolower(c);
    if (up != c)
        std::wcout << "Lower case form of \'" << c << "' is " << up << '\n';
    else
        std::wcout << '\'' << c << "' has no lower case form\n";
}
int main()
{
    std::locale::global(std::locale("en_US.utf8"));
    std::wcout.imbue(std::locale());
    std::wcout << "In US English UTF-8 locale:\n";
    auto& f = std::use_facet<std::ctype<wchar_t>>(std::locale());
    try_lower(f, L'Σ');
    try_lower(f, L'Ɛ');
    try_lower(f, L'A');
    std::wstring str = L"HELLo, wORLD!";
    std::wcout << "Lowercase form of the string '" << str << "' is ";
    f.tolower(&str[0], &str[0] + str.size());
    std::wcout << '\'' << str << "'\n";
}

出力:

In US English UTF-8 locale:
Lower case form of 'Σ' is σ
Lower case form of 'Ɛ' is ɛ
Lower case form of 'A' is a
Lowercase form of the string 'HELLo, wORLD!' is 'hello, world!'

関連項目

do_toupper を呼び出す
(公開メンバ関数)
文字を小文字に変換する
(関数)
ワイド文字を小文字に変換する
(関数)