10 KiB
[locale.codecvt.virtuals]
28 Text processing library [text]
28.3 Localization library [localization]
28.3.4 Standard locale categories [locale.categories]
28.3.4.2 The ctype category [category.ctype]
28.3.4.2.5 Class template codecvt [locale.codecvt]
28.3.4.2.5.3 Virtual functions [locale.codecvt.virtuals]
`result do_out( stateT& state, const internT* from, const internT* from_end, const internT*& from_next, externT* to, externT* to_end, externT*& to_next) const;
result do_in( stateT& state, const externT* from, const externT* from_end, const externT*& from_next, internT* to, internT* to_end, internT*& to_next) const; `
Preconditions: (from <= from_end && to <= to_end) is well-defined and true;state is initialized, if at the beginning of a sequence, or else is equal to the result of converting the preceding characters in the sequence.
Effects: Translates characters in the source range [from, from_end), placing the results in sequential positions starting at destination to.
Converts no more than (from_end - from) source elements, and stores no more than (to_end - to) destination elements.
Stops if it encounters a character it cannot convert.
It always leaves the from_next and to_next pointers pointing one beyond the last element successfully converted.
If it returns noconv,internT and externT are the same type, and the converted sequence is identical to the input sequence [from, from_next),to_next is set equal to to, the value of state is unchanged, and there are no changes to the values in [to, to_end).
A codecvt facet that is used by basic_filebuf ([file.streams]) shall have the property that ifdo_out(state, from, from_end, from_next, to, to_end, to_next) would return ok, where from != from_end, thendo_out(state, from, from + 1, from_next, to, to_end, to_next) shall also return ok, and that ifdo_in(state, from, from_end, from_next, to, to_end, to_next) would return ok, where to != to_end, thendo_in(state, from, from_end, from_next, to, to + 1, to_next) shall also return ok.220
[Note 1:
As a result of operations on state, it can return ok or partial and set from_next == from and to_next != to.
â end note]
Returns: An enumeration value, as summarized in Table 93.
Table 93 — do_in/do_out result values [tab:locale.codecvt.inout]
| ð Value |
Meaning |
|---|---|
| ð ok |
completed the conversion |
| ð partial |
not all source characters converted |
| ð error |
encountered a character in [from, from_end) that cannot be converted |
| ð noconv |
internT and externT are the same type, and input sequence is identical to converted sequence |
A return value of partial, if (from_next == from_end), indicates that either the destination sequence has not absorbed all the available destination elements, or that additional source elements are needed before another destination element can be produced.
Remarks: Its operations on state are unspecified.
[Note 2:
This argument can be used, for example, to maintain shift state, to specify conversion options (such as count only), or to identify a cache of seek offsets.
â end note]
result do_unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
Preconditions: (to <= to_end) is well-defined and true;state is initialized, if at the beginning of a sequence, or else is equal to the result of converting the preceding characters in the sequence.
Effects: Places characters starting at to that should be appended to terminate a sequence when the current stateT is given by state.221
Stores no more than (to_end - to) destination elements, and leaves the to_next pointer pointing one beyond the last element successfully stored.
Returns: An enumeration value, as summarized in Table 94.
Table 94 — do_unshift result values [tab:locale.codecvt.unshift]
| ð Value |
Meaning |
|---|---|
| ð ok |
completed the sequence |
| ð partial |
space for more than to_end - to destination elements was needed to terminate a sequence given the value of state |
| ð error |
an unspecified error has occurred |
| ð noconv |
no termination is needed for this state_type |
int do_encoding() const noexcept;
Returns: -1 if the encoding of the externT sequence is state-dependent; else the constant number of externT characters needed to produce an internal character; or 0 if this number is not a constant.222
bool do_always_noconv() const noexcept;
Returns: true if do_in() and do_out() return noconv for all valid argument values.
codecvt<char, char, mbstate_t> returns true.
int do_length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
Preconditions: (from <= from_end) is well-defined and true;state is initialized, if at the beginning of a sequence, or else is equal to the result of converting the preceding characters in the sequence.
Effects: The effect on the state argument is as if it called do_in(state, from, from_end, from, to, to + max, to) for to pointing to a buffer of at least max elements.
Returns: (from_next - from) wherefrom_next is the largest value in the range [from, from_end] such that the sequence of values in the range [from, from_next) representsmax or fewer valid complete characters of type internT.
The specialization codecvt<char, char, mbstate_t>, returns the lesser of max and (from_end - from).
int do_max_length() const noexcept;
Returns: The maximum value that do_length(state, from, from_end, 1) can return for any valid range [from, from_end) and stateT value state.
The specialization codecvt<char, char, mbstate_t>::do_max_length() returns 1.
Informally, this means that basic_filebuf assumes that the mappings from internal to external characters is 1 to N: that a codecvt facet that is used by basic_filebuf can translate characters one internal character at a time.
Typically these will be characters to return the state to stateT().
If encoding() yields -1, then more than max_length() externT elements can be consumed when producing a single internT character, and additional externT elements can appear at the end of a sequence after those that yield the final internT character.