Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string/wide/towctrans"

From cppreference.com
< cpp‎ | string‎ | wide
m (wc -> ch, {{c}}, headers sorted, fmt, langlinks)
m ({{lc|LC_CTYPE}})
 
Line 5: Line 5:
 
}}
 
}}
  
Maps the wide character {{c|ch}} using the current C locale's LC_CTYPE mapping category identified by {{c|desc}}.
+
Maps the wide character {{c|ch}} using the current C locale's {{lc|LC_CTYPE}} mapping category identified by {{c|desc}}.
  
 
{{cpp/string/wide/wint_t args}}
 
{{cpp/string/wide/wint_t args}}
Line 12: Line 12:
 
{{par begin}}
 
{{par begin}}
 
{{par|ch|the wide character to map}}
 
{{par|ch|the wide character to map}}
{{par|desc|the LC_CTYPE mapping, obtained from a call to {{lc|std::wctrans}}}}
+
{{par|desc|the {{lc|LC_CTYPE}} mapping, obtained from a call to {{lc|std::wctrans}}}}
 
{{par end}}
 
{{par end}}
  
 
===Return value===
 
===Return value===
The mapped value of {{c|ch}} using the mapping identified by {{c|desc}} in LC_CTYPE facet of the current C locale.
+
The mapped value of {{c|ch}} using the mapping identified by {{c|desc}} in {{lc|LC_CTYPE}} facet of the current C locale.
  
 
===Example===
 
===Example===

Latest revision as of 07:38, 18 June 2023

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.

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.

Contents

[edit] Parameters

ch - the wide character to map
desc - the LC_CTYPE mapping, obtained from a call to std::wctrans

[edit] Return value

The mapped value of ch using the mapping identified by desc in LC_CTYPE facet of the current C locale.

[edit] Example

The following example demonstrates katakana to hiragana character mapping.

#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

[edit] See also

looks up a character mapping category in the current C locale
(function) [edit]
C documentation for towctrans