std::ctype<CharT>::tolower, std::ctype<CharT>::do_tolower
來自 cppreference.com
定義於標頭檔案 <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) 對於字元陣列
[
beg,
end)
中的每個字元,如果存在小寫形式,則將其替換為該小寫形式。目錄 |
[編輯] 引數
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 (公有成員函式) | |
將字元轉換為小寫 (函式) | |
將寬字元轉換為小寫 (函式) |