std::tolower(std::locale)(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ 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