[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/locale/codecvt_byname [Back]  [Original]

std::codecvt_byname cppreference.com
cppreference.com

std::codecvt_byname

cppreference.com

<metanoindex/>

<tbody> </tbody>
template< class internT, class externT, class stateT > class codecvt_byname : public std::codecvt<internT, externT, stateT>;
std::codecvt_byname std::codecvt , / .
:
std::codecvt_byname is a std::codecvt facet which encapsulates multibyte/wide character conversion rules of a locale specified at its construction.
Google.
. .
:
Four specializations are provided by the standard library
Google.
. .
<locale>
std::codecvt_byname<char, char, std::mbstate_t>
:
identity conversion
Google.
. .
std::codecvt_byname<char16_t, char, std::mbstate_t>
UTF-16 UTF-8 ( C++11)
:
conversion between UTF-16 and UTF-8 ( C++11)
Google.
. .
std::codecvt_byname<char32_t, char, std::mbstate_t>
UTF-32 UTF-8 ( C++11)
:
conversion between UTF-32 and UTF-8 ( C++11)
Google.
. .
std::codecvt_byname<wchar_t, char, std::mbstate_t>
, , ,
:
locale-specific conversion between wide string and narrow, possibly multibyte, string
Google.
. .

-

codecvt_byname
:
constructs a new codecvt_byname facet
Google.
. .

(public -)
codecvt_byname
:
destructs a codecvt_byname facet
Google.
. .

(protected -)

std::codecvt

Member types

intern_type internT
extern_type externT
state_type stateT

Member objects

:
Member name
Google.
. .
Type
id () std::locale::id

Member functions

do_out
:
invokes do_out
Google.
. .

(public - std::codecvt) []
do_in
:
invokes do_in
Google.
. .

(public - std::codecvt) []
do_unshift
:
invokes do_unshift
Google.
. .

(public - std::codecvt) []
do_encoding
:
invokes do_encoding
Google.
. .

(public - std::codecvt) []
do_always_noconv
:
invokes do_always_noconv
Google.
. .

(public - std::codecvt) []
do_length
:
invokes do_length
Google.
. .

(public - std::codecvt) []
do_max_length
:
invokes do_max_length
Google.
. .

(public - std::codecvt) []

Protected member functions

[virtual]
internT externT, ,
:
converts a string from internT to externT, such as when writing to file
Google.
. .

(virtual protected std::codecvt -) []
[virtual]
externT internT, ,
:
converts a string from externT to internT, such as when reading from file
Google.
. .

(virtual protected std::codecvt -) []
[virtual]
externT
:
generates the termination character sequence of externT characters for incomplete conversion
Google.
. .

(virtual protected std::codecvt -) []
[virtual]
externT , internT ,
:
returns the number of externT characters necessary to produce one internT character, if constant
Google.
. .

(virtual protected std::codecvt -) []
,
:
tests if the facet encodes an identity conversion for all valid argument values
Google.
. .

(virtual protected std::codecvt -) []
[virtual]
externT , internT
:
calculates the length of the externT string that would be consumed by conversion into given internT buffer
Google.
. .

(virtual protected std::codecvt -) []
externT , internT
:
returns the maximum number of externT characters that could be converted into a single internT character
Google.
. .

(virtual protected std::codecvt -) []


std::codecvt_base

enum result { ok, partial, error, noconv };
:
Unscoped enumeration type
Google.
. .
:
Enumeration constant
Google.
. .
Definition
ok
:
conversion was completed with no error
Google.
. .
partial
:
not all source characters were converted
Google.
. .
error
:
encountered an invalid character
Google.
. .
noconv
,
:
no conversion required, input and output types are the same
Google.
. .

GB18030- , codecvt GB18030-
:
This example demonstrates reading a GB18030-encoded file using the codecvt facet from a GB18030-aware locale
Google.
. .

#include <iostream>
#include <fstream>
#include <string>
#include <locale>
int main()
{
    // GB18030 narrow multibyte encoding
    std::ofstream("text.txt") << "\x7a"              // letter 'z', U+007a
                                 "\x81\x30\x89\x38"  // letter '', U+00df
                                 "\xcb\xae"          // CJK ideogram '' (water), U+6c34
                                 "\x94\x32\xbc\x35"; // musical sign '' (segno), U+1d10b
    std::wifstream fin("text.txt");
    fin.imbue(std::locale(fin.getloc(),
              new std::codecvt_byname<wchar_t, char, std::mbstate_t>("zh_CN.gb18030")));
    for(wchar_t c; fin.get(c); )
        std::cout << std::hex << std::showbase << c << '\n';
}

:

0x7a
0xdf
0x6c34
0x1d10b

.

, UTF-8, UTF-16, UTF-32
( ) []

Web Proxy Viewer  |  New URL  |  Original Page