std::toupper(std::locale)(3)
π NAME π
std::toupper(std::locale) β literally std::toupper(std::locale), bestie. Weβre in the C++ Standard Libary manual, page (3), and this function is serving self-titled main character energy. Periodt.
β¨ Synopsis β¨
Defined in header <locale>
template< class CharT >
CharT toupper( CharT ch, const locale& loc );
Converts the character ch to uppercase if possible, using the conversion rules specified by the given localeβs std::ctype facet. Slay.
π Parameters π
chβ character. The little guy getting uppercased.locβ locale. The vibe check that decides how the conversion goes.
π Return value π
Returns the uppercase form of ch if one is listed in the locale. Otherwise it returns ch unchanged β no glow-up, just the same character back. π
π§ Notes π§
Only 1:1 character mapping can be performed by this function. Like, it canβt do glow-up magic that turns one character into a whole string.
For example, the uppercase form of 'Γ' is (with some exceptions) the two-character string "SS", which cannot be obtained by std::toupper. Itβs giving βbestie I can only do one-for-one,β no cap. π
π οΈ Possible implementation π οΈ
template<class CharT>
CharT toupper(CharT ch, const std::locale& loc)
{
return std::use_facet<std::ctype<CharT>>(loc).toupper(ch);
}
π Example π
// Run this code
#include <cwctype>
#include <iostream>
#include <locale>
int main()
{
wchar_t c = L'\u017f'; // Latin small letter Long S ('ΕΏ')
std::cout << std::hex << std::showbase;
std::cout << "in the default locale, toupper(" << (std::wint_t)c << ") = "
<< (std::wint_t)std::toupper(c, std::locale()) << '\n';
std::cout << "in Unicode locale, toupper(" << (std::wint_t)c << ") = "
<< (std::wint_t)std::toupper(c, std::locale("en_US.utf8")) << '\n';
}
π Possible output π
in the default locale, toupper(0x17f) = 0x17f
in Unicode locale, toupper(0x17f) = 0x53
π See also π
tolower(std::locale)β converts a character to lowercase using thectypefacet of a locale (function template).toupperβ converts a character to uppercase (function).towupperβ converts a wide character to uppercase (function).
mwah π β source: http://cppreference.com, version/date stamp: 2024.06.10. Stay cased, stay iconic π«Άβ¨
π¦ 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