Namespaces
Variants

std:: toupper (std::locale)

From cppreference.net
ヘッダーで定義 <locale>
template < class CharT >
CharT toupper ( CharT ch, const locale & loc ) ;

指定されたロケールの std::ctype ファセットで定義された変換規則を使用して、可能であれば文字 ch を大文字に変換します。

目次

パラメータ

ch - 文字
loc - ロケール

戻り値

ロケールにリストされている場合は ch の大文字形式を返し、それ以外の場合は ch を変更せずに返します。

注記

この関数は1:1の文字マッピングのみ実行できます。例えば、'ß'の大文字形式は(一部の例外を除き)2文字の文字列"SS"ですが、これは std::toupper では取得できません。

実装例

template<class CharT>
CharT toupper(CharT ch, const std::locale& loc)
{
    return std::use_facet<std::ctype<CharT>>(loc).toupper(ch);
}

#include <cwctype>
#include <iostream>
#include <locale>
int main()
{
    wchar_t c = L'\u017f'; // Latin small letter Long S ('ſ')
    std::cout << std::hex << std::showbase;
    std::cout << "in the default locale, toupper(" << (std::wint_t)c << ") = "
              << (std::wint_t)std::toupper(c, std::locale()) << '\n';
    std::cout << "in Unicode locale, toupper(" << (std::wint_t)c << ") = "
              << (std::wint_t)std::toupper(c, std::locale("en_US.utf8")) << '\n';
}

出力例:

in the default locale, toupper(0x17f) = 0x17f
in Unicode locale, toupper(0x17f) = 0x53

関連項目

ロケールの ctype ファセットを使用して文字を小文字に変換する
(関数テンプレート)
文字を大文字に変換する
(関数)
ワイド文字を大文字に変換する
(関数)