std::ctype:...:do_tolower(3)
π
std::ctype::tolower / std::ctype::do_tolower β a C++ Standard Libary moment π
ok so bestie, we're in <locale> land today and this one is genuinely iconic. it's the manual page for std::ctype::tolower and std::ctype::do_tolower β like the lowercase-ification girlies of the C++ standard library β¨
πΈ NAME πΈ
std::ctype::tolower, std::ctype::do_tolower β literally just std::ctype::tolower,std::ctype::do_tolower, no notes π
β¨ SYNOPSIS β¨
Defined in header <locale> β don't forget it, slay π«Ά
public:
(1)
CharT tolower( CharT c ) const;
public:
(2)
const CharT* tolower( CharT* beg, const CharT* end ) const;
protected:
(3)
virtual CharT do_tolower( CharT c ) const;
protected:
(4)
virtual const CharT* do_tolower( CharT* beg, const CharT* end ) const;
So here's the tea, numbered like the icons they are:
- and 2. are the public member functions, and what do they do? they call the protected virtual member function
do_tolowerof the most derived class. delegation, we love to see it π - converts the character
cto lower case if a lower case form is defined by this locale. very "if you know, you know" of it. - for every character in the character array
[beg, end), for which a lower case form exists, replaces the character with that lower case form. glow-down era π
π¦ PARAMETERS π¦
cβ character to convertbegβ pointer to the first character in an array of characters to convertendβ one past the end pointer for the array of characters to convert
π RETURN VALUE π
- 1, 3) β the lower case character, or
cif no lower case form is listed by this locale (no glow-down for you, bestie, you stay as you are π) - 2, 4) β
end
π NOTES π
β οΈ okay listen up, this is the important bit: only 1:1 character mapping can be performed by this function. so like, the Greek uppercase letter'Ξ£'has two lowercase forms depending on the position in a word:'Ο'and'Ο'. a call todo_tolowercannot be used to obtain the correct lowercase form in this case. sobbing π it's just not built for that level of nuance.
π EXAMPLE π
// Run this code
#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'οΌ‘');
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";
}
(yes the variable is called up even though it holds the lowercase form β main character energy, we don't question the naming π)
π OUTPUT π
In US English UTF-8 locale:
Lower case form of 'Ξ£' is Ο
Lower case form of 'Ζ' is Ι
Lower case form of 'οΌ‘' is ο½
Lowercase form of the string 'HELLo, wORLD!' is 'hello, world!'
look at 'hello, world!' fully lowercase and thriving π₯Ήπ
π SEE ALSO π
toupperβ invokesdo_toupper(public member function)tolowerβ converts a character to lowercase (function)towlowerβ converts a wide character to lowercase (function)
that's the whole vibe check bestie β this page came from cppreference.com, and the version/date stamp on it is 2024.06.10. go forth and lowercase responsibly β¨π¦π π½
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms