std::towlower(3)
π std::towlower β yes bestie, it's giving lowercase
okay so real quick, this whole page lives in the C++ Standard Libary manual (that's literally how it's spelled up top, i'm not fixing it, it's iconic π). the function we're stanning today is std::towlower, and it's exactly what it sounds like: wide char goes in, lowercase wide char comes out. slay.
β¨ NAME β¨
std::towlower β literally std::towlower. that's the name. that's the whole name. short and sweet, main character energy π
πΈ Synopsis πΈ
so first things first, where does she live? she's defined in the header <cwctype>. periodt.
std::wint_t towlower( std::wint_t ch );
what she does: converts the given wide character to lowercase, if possible. (that "if possible" is doing a lot of work, keep reading π)
β οΈ okay so this is the important scary part, no cap: if the value ofchis neither representable as awchar_tnor equal to the value of the macroWEOF, the behavior is undefined. like, undefined undefined. don't do it. π©
π Parameters π
chβ the wide character to be converted. that's it, that's the whole list bestie, she's low maintenance π«Ά
π¦ Return value π¦
you get back the lowercase version of ch β or, if no lowercase version is listed in the current C locale, you just get ch back unmodified. no lowercase fit found? she returns home unchanged, we respect that π
π Notes π
okay so this is the tea: this function can only do 1:1 character mapping. only one-to-one. nothing fancy.
the example they give (and it's such a good example, obsessed): the Greek uppercase letter 'Ξ£' has two lowercase forms depending on where it sits in a word β 'Ο' and 'Ο'. so a call to std::towlower cannot be used to get the correct lowercase form in that case. it just can't. it's not built for that, don't come for her π
also, ISO 30112 specifies which pairs of Unicode characters are included in this mapping. iykyk β
π Example π
// Run this code β go off, run it:
#include <clocale>
#include <cwctype>
#include <iostream>
int main()
{
wchar_t c = L'\u0190'; // Latin capital open E ('Ζ')
std::cout << std::hex << std::showbase;
std::cout << "in the default locale, towlower("
<< static_cast<std::wint_t>(c) << ") = "
<< std::towlower(c) << '\n';
std::setlocale(LC_ALL, "en_US.utf8");
std::cout << "in Unicode locale, towlower("
<< static_cast<std::wint_t>(c) << ") = "
<< std::towlower(c) << '\n';
}
note the cute little L'\u0190' β that's the Latin capital open E ('Ζ') in case you were wondering π
π§ Output:
in the default locale, towlower(0x190) = 0x190
in Unicode locale, towlower(0x190) = 0x25b
see how in the default locale she just hands it right back? 0x190 β 0x190, no change, nothing to map to. but once you std::setlocale(LC_ALL, "en_US.utf8")? boom, 0x190 β 0x25b. the glow-up is real π₯
π See also π
towupperβ converts a wide character to uppercase (function). the sister function, equally iconic.tolower(std::locale)β converts a character to lowercase using thectypefacet of a locale (function template). fancy locale-aware version, she's got range.tolowerβ converts a character to lowercase (function). the narrow-char cousin.- C documentation for
towlowerβ yes, C has one too, the family reunion is complete πΈ
okay that's the whole page, you're officially educated, go forth and lowercase responsibly π
signed off with love from http://cppreference.com, dated 2024.06.10, page std::towlower(3) β mwah, catch you in the next manpage bestie π«Άβ¨
π¦ 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