std::toupper(std::locale)
来自cppreference.com
| 在标头 <locale> 定义
|
||
| |
||
用给定本地环境的 std::ctype 刻面所指定的转换规则,若可能则转换字符 ch 为大写。
参数
| ch | - | 字符 |
| loc | - | 本地环境 |
返回值
若 ch 的大写形式列于本地环境则返回它,否则返回不更改的 ch。
注解
此函数只能进行 1:1 字符映射,例如 'ß' 的大写形式(有一些例外)是双字符字符串 "SS",它无法以 do_toupper 获得。
可能的实现
template<class CharT>
CharT toupper(CharT ch, const std::locale& loc)
{
return std::use_facet<std::ctype<CharT>>(loc).toupper(ch);
}
|
示例
Run this code
#include <cwctype>
#include <iostream>
#include <locale>
int main()
{
wchar_t c = L'\u017f'; // 拉丁文小写字母长 S ('ſ')
std::cout << std::hex << std::showbase;
std::cout << "默认本地环境中,toupper(" << (std::wint_t)c << ") = "
<< (std::wint_t)std::toupper(c, std::locale()) << '\n';
std::cout << "Unicode 本地环境中,toupper(" << (std::wint_t)c << ") = "
<< (std::wint_t)std::toupper(c, std::locale("en_US.utf8")) << '\n';
}
可能的输出:
默认本地环境中,toupper(0x17f) = 0x17f
Unicode 本地环境中,toupper(0x17f) = 0x53
参阅
用本地环境的 ctype 刻面将字符转换成小写 (函数模板) | |
| 转换字符为大写 (函数) | |
| 转换宽字符为大写 (函数) |