std::ctype<CharT>::toupper, std::ctype<CharT>::do_toupper
From cppreference.com
| ヘッダー <locale> で定義 |
||
| public: CharT toupper( CharT c ) const; |
(1) | |
| public: const CharT* toupper( CharT* beg, const CharT* end ) const; |
(2) | |
| protected: virtual CharT do_toupper( CharT c ) const; |
(3) | |
| protected: virtual const CharT* do_toupper( CharT* beg, const CharT* end ) const; |
(4) | |
1,2) 公開メンバ関数。最も派生したクラスの保護仮想メンバ関数
do_toupperを呼び出します。3) このロケールによって大文字の形式が定義されている場合、文字cを大文字に変換します。
4) 文字配列
[beg, end) 内の、大文字の形式が存在する各文字を、その大文字の形式で置き換えます。目次 |
[編集] パラメータ
| c | - | 変換する文字 |
| beg | - | 変換する文字配列の最初の文字へのポインタ |
| end | - | 変換する文字配列の終端の次を指すポインタ |
[編集] 戻り値
1,3) 大文字の文字、またはこのロケールで大文字の形式がリストされていない場合はc。
2,4)
end[編集] 注意
この関数で実行できるのは1対1の文字マッピングのみです。たとえば、「ß」の大文字形式は2文字の文字列「SS」ですが(例外もあります - «Capital ẞ»を参照)、これはdo_toupperでは取得できません。
[編集] 例
このコードを実行
#include <iostream> #include <locale> void try_upper(const std::ctype<wchar_t>& f, wchar_t c) { wchar_t up = f.toupper(c); if (up != c) std::wcout << "Upper case form of \'" << c << "' is " << up << '\n'; else std::wcout << '\'' << c << "' has no upper 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_upper(f, L's'); try_upper(f, L'ſ'); try_upper(f, L'δ'); try_upper(f, L'ö'); try_upper(f, L'ß'); std::wstring str = L"Hello, World!"; std::wcout << "Uppercase form of the string '" << str << "' is "; f.toupper(&str[0], &str[0] + str.size()); std::wcout << '\'' << str << "'\n"; }
出力
In US English UTF-8 locale: Upper case form of 's' is S Upper case form of 'ſ' is S Upper case form of 'δ' is Δ Upper case form of 'ö' is Ö 'ß' has no upper case form Uppercase form of the string 'Hello, World!' is 'HELLO, WORLD!'
[編集] 関連項目
do_tolowerを呼び出します。(公開メンバ関数) | |
| 文字を大文字に変換する (関数) | |
| ワイド文字を大文字に変換する (関数) |