std::tolower(std::locale)
来自cppreference.com
| 在标头 <locale> 定义
|
||
| |
||
用给定本地环境的 std::ctype 刻面所指定的转换规则,若可能则转换字符 ch 为小写。
参数
| ch | - | 字符 |
| loc | - | 本地环境 |
返回值
若 ch 的小写形式列于本地环境则返回它,否则返回不更改的 ch。
注解
此函数只能进行 1:1 字符映射。例如希腊文大写字母 'Σ' 拥有两个小写形式:'σ' 与 'ς',使用哪一个取决于其在词中的位置。此情况下对 std::do_tolower 的调用不能获得正确的小写形式。
可能的实现
template<class CharT>
CharT tolower(CharT ch, const std::locale& loc)
{
return std::use_facet<std::ctype<CharT>>(loc).tolower(ch);
}
|
示例
运行此代码
#include <cwctype>
#include <iostream>
#include <locale>
int main()
{
wchar_t c = L'\u0190'; // 拉丁文大写开 E ('Ɛ')
std::cout << std::hex << std::showbase;
std::cout << "默认本地环境中,tolower(" << (std::wint_t)c << ") = "
<< (std::wint_t)std::tolower(c, std::locale()) << '\n';
std::cout << "Unicode 本地环境中,tolower(" << (std::wint_t)c << ") = "
<< (std::wint_t)std::tolower(c, std::locale("en_US.utf8")) << '\n';
}
可能的输出:
默认本地环境中,tolower(0x190) = 0x190
Unicode 本地环境中,tolower(0x190) = 0x25b
参阅
用本地环境的 ctype 刻面将字符转换成大写 (函数模板) | |
| 转换字符为小写 (函数) | |
| 转换宽字符为小写 (函数) |