std::tolower(std::locale)(3)
π std::tolower(std::locale) β C++ Standard Libary edition π
okay so bestie, welcome to the std::tolower(std::locale)(3) page. The manual name is literally C++ Standard Libary (yes, that exact typo, weβre not fixing it, itβs part of the lore π). Itβs the C++ Standard Library function that lowercases a character using a localeβs std::ctype facet. Letβs get into it β¨
NAME
std::tolower(std::locale)βstd::tolower(std::locale)(the name, the whole name, and nothing but the name π )
Synopsis
Defined in header <locale>
template< class CharT >
CharT tolower( CharT ch, const locale& loc );
Converts the character ch to lowercase if possible, using the conversion rules specified by the given localeβs std::ctype facet. Slay. π
Parameters
chβ character.locβ locale.
Return value
Returns the lowercase form of ch if one is listed in the locale. Otherwise? It returns ch unchanged, no cap. π«Ά
Notes
Only 1:1 character mapping can be performed by this function, bestie. For example, the Greek uppercase letter 'Ξ£' has two lowercase forms, depending on the position in a word: 'Ο' and 'Ο'. A call to std::tolower cannot be used to obtain the correct lowercase form in this case. Thatβs the tea β.
Possible implementation
Hereβs the lowkey possible implementation, exactly as the page gives it:
template<class CharT>
CharT tolower(CharT ch, const std::locale& loc)
{
return std::use_facet<std::ctype<CharT>>(loc).tolower(ch);
}
Example
Run this code, bestie:
// Run this code
#include <cwctype>
#include <iostream>
#include <locale>
int main()
{
wchar_t c = L'\u0190'; // Latin capital open E ('Ζ')
std::cout << std::hex << std::showbase;
std::cout << "in the default locale, tolower(" << (std::wint_t)c << ") = "
<< (std::wint_t)std::tolower(c, std::locale()) << '\n';
std::cout << "in Unicode locale, tolower(" << (std::wint_t)c << ") = "
<< (std::wint_t)std::tolower(c, std::locale("en_US.utf8")) << '\n';
}
Possible output
in the default locale, tolower(0x190) = 0x190
in Unicode locale, tolower(0x190) = 0x25b
See also
toupper(std::locale)β converts a character to uppercase using the ctype facet of a locale (function template).tolowerβ converts a character to lowercase (function).towlowerβ converts a wide character to lowercase (function).
mwah π β source/version/date check, exactly: http://cppreference.com, 2024.06.10, and the page is std::tolower(std::locale)(3). Byeee, go 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