std::towctrans(3)

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

πŸ’– std::towctrans(3) πŸ’–

okay so this is the std::towctrans(3) page from the C++ Standard Libary manual β€” yes, that spelling is the manual’s, bestie 🫢 β€” and it’s all about mapping wide characters through the current C locale’s LC_CTYPE mapping category. iconic behavior, honestly ✨


🌸 NAME 🌸

std::towctrans β€” std::towctrans (that’s literally the name, no cap πŸ’…)


✨ Synopsis ✨

Defined in header <cwctype>:

std::wint_t towctrans( std::wint_t ch, std::wctrans_t desc );

Maps the wide character ch using the current C locale’s LC_CTYPE mapping category identified by desc πŸ’–

careful, bestie: if the value of ch is neither representable as a wchar_t nor equal to the value of the macro WEOF, the behavior is undefined πŸ™ˆπŸ’€

πŸ’… Parameters πŸ’…

  • ch β€” the wide character to map πŸŽ€
  • desc β€” the LC_CTYPE mapping, obtained from a call to std::wctrans ✨

πŸ¦‹ Return value πŸ¦‹

The mapped value of ch using the mapping identified by desc in the LC_CTYPE facet of the current C locale. that’s the whole vibe 🫢


πŸ”₯ Example πŸ”₯

The following example demonstrates katakana to hiragana character mapping β€” literally so cute 🌸

Run this code, bestie πŸ‘‡

#include <algorithm>
#include <clocale>
#include <cwctype>
#include <iostream>

std::wstring tohira(std::wstring str)
{
    std::transform(str.begin(), str.end(), str.begin(), [](wchar_t c)
    {
         return std::towctrans(c, std::wctrans("tojhira"));
    });
    return str;
}

int main()
{
    std::setlocale(LC_ALL, "ja_JP.UTF-8");
    std::wstring kana = L"γƒ’γƒ©γ‚¬γƒŠ";
    std::wcout << "katakana characters " << kana
               << " are " << tohira(kana) << " in hiragana\n";
}

πŸ“ Output πŸ“

katakana characters γƒ’γƒ©γ‚¬γƒŠ are γ²γ‚‰γŒγͺ in hiragana

πŸ‘‘ See also πŸ‘‘

  • wctrans β€” looks up a character mapping category in the current C locale (function) πŸ’–
  • C documentation for towctrans ✨

mwah πŸ’‹ this page came from http://cppreference.com, dated 2024.06.10, and it’s the std::towctrans(3) page 🫢🌈

πŸ“¦ where this page comes from