STD::CODECVT(3cxx)

✨ std::codecvt< _InternT, _ExternT, _StateT >(3cxx) ✨

okay bestie, so this is from the <locale> library manual, and it's literally the std::codecvt page πŸ’… it's giving "character set conversion royalty" and honestly? we're obsessed.


🌸 NAME 🌸

std::codecvt< _InternT, _ExternT, _StateT > β€” the Primary class template codecvt. that's it, that's the vibe πŸŽ€


✨ SYNOPSIS ✨

#include <locale>

so first things first, it Inherits from std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >. and guess what β€” it's also Inherited by std::codecvt_byname< _InternT, _ExternT, _StateT >. family tree is giving main character energy fr fr 🌈

πŸ’– Public Types

  • typedef _ExternT extern_type β€” the external (think: on-disk, out-in-the-world) character type, slay
  • typedef _InternT intern_type β€” the internal (think: in-memory, cozy) character type
  • typedef codecvt_base::result result β€” the result enum it uses, iconic
  • typedef _StateT state_type β€” the conversion state type, periodt

πŸ”₯ Public Member Functions

  • codecvt (__c_locale __cloc, size_t __refs=0) β€” constructor that takes a C locale and refs, no cap
  • codecvt (size_t __refs=0) β€” the plain refs-only constructor, lowkey the default one
  • bool always_noconv () const throw () β€” tells you if this facet never actually converts anything
  • int encoding () const throw () β€” how many extern chars per intern char (or a fun negative value, k)
  • result in (state_type &__state, const extern_type *__from, const extern_type *__from_end, const extern_type *&__from_next, intern_type *__to, intern_type *__to_end, intern_type *&__to_next) const β€” Convert from external to internal character set. the classic glow-up from extern to intern πŸ’–
  • int length (state_type &__state, const extern_type *__from, const extern_type *__end, size_t __max) const β€” how many chars would actually get converted, ngl it's the vibe check of conversions
  • int max_length () const throw () β€” the max bytes/units a single intern char can ever expand into, big yikes energy
  • result out (state_type &__state, const intern_type *__from, const intern_type *__from_end, const intern_type *&__from_next, extern_type *__to, extern_type *__to_end, extern_type *&__to_next) const β€” Convert from internal to external character set. the reverse glow-up, we love a two-way queen ✨
  • result unshift (state_type &__state, extern_type *__to, extern_type *__to_end, extern_type *&__to_next) const β€” Reset conversion state. the cleanup era, we stan a tidy state 🧚

πŸ‘‘ Static Public Attributes

  • static locale::id id β€” the locale id, the one and only, iconic as always

πŸ¦‹ Protected Member Functions

  • virtual bool do_always_noconv () const throw () β€” the overridable version of always_noconv, your fave hook
  • virtual int do_encoding () const throw () β€” the overridable encoding hook, go off
  • virtual result do_in (state_type &__state, const extern_type *__from, const extern_type *__from_end, const extern_type *&__from_next, intern_type *__to, intern_type *__to_end, intern_type *&__to_next) const β€” the actual conversion logic for in, this is where the real work happens fr fr
  • virtual int do_length (state_type &, const extern_type *__from, const extern_type *__end, size_t __max) const β€” the length override hook, note it doesn't even name the state param, periodt
  • virtual int do_max_length () const throw () β€” max_length override hook, your fave
  • virtual result do_out (state_type &__state, const intern_type *__from, const intern_type *__from_end, const intern_type *&__from_next, extern_type *__to, extern_type *__to_end, extern_type *&__to_next) const β€” Convert from internal to external character set. the do_out hook, she's the moment πŸ’…
  • virtual result do_unshift (state_type &__state, extern_type *__to, extern_type *__to_end, extern_type *&__to_next) const β€” the unshift override hook, reset era part 2

🌈 Static Protected Member Functions

  • static __c_locale _S_clone_c_locale (__c_locale &__cloc) throw () β€” clone a C locale like a lil copy-paste fairy 🧚
  • static void _S_create_c_locale (__c_locale &__cloc, const char *__s, __c_locale __old=0) β€” make a C locale from a name, the whole __old=0 default is giving safety net
  • static void _S_destroy_c_locale (__c_locale &__cloc) β€” destroy it, goodbye bestie πŸ‘‹
  • static __c_locale _S_get_c_locale () β€” grab the C locale, yas
  • static const char * _S_get_c_name () throw () β€” get the C locale's name string, iconic
  • static __c_locale _S_lc_ctype_c_locale (__c_locale __cloc, const char *__s) β€” the ctype flavor of c locale stuff, lowkey specific

πŸ“ Protected Attributes

  • __c_locale _M_c_locale_codecvt β€” the protected C locale member, living her best protected life

πŸ’œ Detailed Description πŸ’œ

template<typename _InternT, typename _ExternT, typename _StateT>
    class std::codecvt< _InternT, _ExternT, _StateT >

okay so this is the Primary class template codecvt β€” and bestie, read the fine print: NB: Generic, mostly useless implementation. 😭 like not me finding out the base template is literally decorative. fr fr though, that's just how it is β€” the real magic lives in the specializations and the codecvt_byname child. it's giving "placeholder era" but make it ✨ standard-compliant ✨


part 1 of 2, bestie β€” stay tuned πŸ’–

πŸ’… Member Function Documentation πŸ’…

Okay bestie, this is the function-by-function tea. Every single one is here, no skipping, no cap. ✨

do_always_noconv πŸ’€

template<typename _InternT , typename _ExternT , typename _StateT > virtual
       bool std::codecvt< _InternT, _ExternT, _StateT >::do_always_noconv ()
       const [protected],  [virtual]

This one is [protected] and [virtual], and it implements std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >. That’s literally all the page gives us β€” no extra lore, no cap.


do_encoding πŸŽ€

template<typename _InternT , typename _ExternT , typename _StateT > virtual
       int std::codecvt< _InternT, _ExternT, _StateT >::do_encoding () const
       [protected],  [virtual]

Also [protected] and [virtual], and it implements std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >. Short and mysterious, periodt.


do_in πŸ¦‹

template<typename _InternT , typename _ExternT , typename _StateT > virtual
       result std::codecvt< _InternT, _ExternT, _StateT >::do_in (state_type &
       __state, const extern_type * __from, const extern_type * __from_end,
       const extern_type *& __from_next, intern_type * __to, intern_type *
       __to_end, intern_type *& __to_next) const [protected],  [virtual]

[protected], [virtual], and it implements std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >. That’s the whole vibe for this one.


do_length 🌸

template<typename _InternT , typename _ExternT , typename _StateT > virtual
       int std::codecvt< _InternT, _ExternT, _StateT >::do_length (state_type
       &, const extern_type * __from, const extern_type * __end, size_t __max)
       const [protected],  [virtual]

[protected], [virtual], and it implements std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >. Iconic brevity.


do_max_length ⭐

template<typename _InternT , typename _ExternT , typename _StateT > virtual
       int std::codecvt< _InternT, _ExternT, _StateT >::do_max_length () const
       [protected],  [virtual]

[protected], [virtual], and it implements std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >. That’s it, bestie.


do_out πŸ”₯

template<typename _InternT , typename _ExternT , typename _StateT > virtual
       result std::codecvt< _InternT, _ExternT, _StateT >::do_out (state_type &
       __state, const intern_type * __from, const intern_type * __from_end,
       const intern_type *& __from_next, extern_type * __to, extern_type *
       __to_end, extern_type *& __to_next) const [protected],  [virtual]

[protected], [virtual].

Convert from internal to external character set. Converts input string of intern_type to output string of extern_type. This function is a hook for derived classes to change the value returned.

See also: out for more information.

It implements std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >.


do_unshift 🧚

template<typename _InternT , typename _ExternT , typename _StateT > virtual
       result std::codecvt< _InternT, _ExternT, _StateT >::do_unshift
       (state_type & __state, extern_type * __to, extern_type * __to_end,
       extern_type *& __to_next) const [protected],  [virtual]

[protected], [virtual], and it implements std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >. Another short queen.


in 🌈

template<typename _InternT , typename _ExternT , typename _StateT > result
       std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >::in
       (state_type & __state, const extern_type * __from, const extern_type *
       __from_end, const extern_type *& __from_next, intern_type * __to,
       intern_type * __to_end, intern_type *& __to_next) const [inline],
       [inherited]

[inline], [inherited].

Convert from external to internal character set. Converts input string of extern_type to output string of intern_type. This is analogous to mbsrtowcs. It does this by calling codecvt::do_in.

The source and destination character sets are determined by the facet's locale, internal and external types.

The characters in [from,from_end) are converted and written to [to,to_end). from_next and to_next are set to point to the character following the last successfully converted character, respectively. If the result needed no conversion, from_next and to_next are not affected.

The state argument should be initialized if the input is at the beginning and carried from a previous call if continuing conversion. There are no guarantees about how state is used.

The result returned is a member of codecvt_base::result. If all the input is converted, returns codecvt_base::ok. If no conversion is necessary, returns codecvt_base::noconv. If the input ends early or there is insufficient space in the output, returns codecvt_base::partial. Otherwise the conversion failed and codecvt_base::error is returned.

Parameters

  • __state β€” Persistent conversion state data.
  • __from β€” Start of input.
  • __from_end β€” End of input.
  • __from_next β€” Returns start of unconverted data.
  • __to β€” Start of output buffer.
  • __to_end β€” End of output buffer.
  • __to_next β€” Returns start of unused output area.

Returns

codecvt_base::result.


out πŸ’–

template<typename _InternT , typename _ExternT , typename _StateT > result
       std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >::out
       (state_type & __state, const intern_type * __from, const intern_type *
       __from_end, const intern_type *& __from_next, extern_type * __to,
       extern_type * __to_end, extern_type *& __to_next) const [inline],
       [inherited]

[inline], [inherited].

Convert from internal to external character set. Converts input string of intern_type to output string of extern_type. This is analogous to wcsrtombs. It does this by calling codecvt::do_out.

The source and destination character sets are determined by the facet's locale, internal and external types.

The characters in [from,from_end) are converted and written to [to,to_end). from_next and to_next are set to point to the character following the last successfully converted character, respectively. If the result needed no conversion, from_next and to_next are not affected.

The state argument should be initialized if the input is at the beginning and carried from a previous call if continuing conversion. There are no guarantees about how state is used.

The result returned is a member of codecvt_base::result. If all the input is converted, returns codecvt_base::ok. If no conversion is necessary, returns codecvt_base::noconv. If the input ends early or there is insufficient space in the output, returns codecvt_base::partial. Otherwise the conversion failed and codecvt_base::error is returned.

Parameters

  • __state β€” Persistent conversion state data.
  • __from β€” Start of input.
  • __from_end β€” End of input.
  • __from_next β€” Returns start of unconverted data.
  • __to β€” Start of output buffer.
  • __to_end β€” End of output buffer.
  • __to_next β€” Returns start of unused output area.

Returns

codecvt_base::result.

References

std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >::do_out().


unshift 🫢

template<typename _InternT , typename _ExternT , typename _StateT > result
       std::__codecvt_abstract_base< _InternT, _ExternT, _StateT >::unshift
       (state_type & __state, extern_type * __to, extern_type * __to_end,
       extern_type *& __to_next) const [inline],  [inherited]

[inline], [inherited].

Reset conversion state. Writes characters to output that would restore state to initial conditions. The idea is that if a partial conversion occurs, then converting the characters written by this function would leave the state in initial conditions, rather than partial conversion state. It does this by calling codecvt::do_unshift().

For example, if 4 external characters always converted to 1 internal character, and input to in() had 6 external characters with state saved, this function would write two characters to the output and set the state to initialized conditions.

The source and destination character sets are determined by the facet's locale, internal and external types.

The result returned is a member of codecvt_base::result. If the state could be reset and data written, returns codecvt_base::ok. If no conversion is necessary, returns codecvt_base::noconv. If the output has insufficient space, returns codecvt_base::partial. Otherwise the reset failed and codecvt_base::error is returned.

Parameters

  • __state β€” Persistent conversion state data.
  • __to β€” Start of output buffer.
  • __to_end β€” End of output buffer.
  • __to_next β€” Returns start of unused output area.

Returns

codecvt_base::result.


πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for libstdc++ from the source code.

πŸ’– That’s the whole page, bestie! Source: libstdc++; footer/handle situation: libstdstd::codecvt< ...ernT, _StateT >(3cxx); date: none shown in this copy. Mwah! πŸ’…

πŸ“¦ where this page comes from