命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | 本地化‎ | ctype
 
 
 
 
 
定义于头文件 <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) 对于字符数组 [begend) 中的每个字符,如果存在小写形式,则将其替换为该小写形式。

目录

[编辑] 参数

c - 要转换的字符
beg - 指向要转换的字符数组中第一个字符的指针
end - 要转换的字符数组的末尾指针(不包含)

[编辑] 返回值

1,3) 小写字符,如果此区域设置未列出小写形式,则为 c
2,4) end

[编辑] 注意

此函数只能执行 1:1 字符映射,例如,希腊语大写字母 'Σ' 有两种小写形式,取决于在单词中的位置:'σ' 和 'ς'。在这种情况下,不能使用 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
(公有成员函数) [编辑]
将字符转换为小写
(函数) [编辑]
将宽字符转换为小写
(函数) [编辑]