count_as_decoded

ztd::text::count_as_decoded is a function that takes an input sequence of code_units and attempts to count them, according to the error handler that is given. Because the error handler is included as part of the function call (and is provided by default is one is not passed in), the count operation will also continue to count if the error handler sets the error_code member of the result to ztd::text::encoding_error::ok but still performs some action. This is, for example, the case with ztd::text::replacement_handler_t - output replacement code units or code points will be counted as part of the final count and returned with result.error_code == ztd::text::encoding_error::ok. You can differentiate error-less text from non-error text by checking result.errors_were_handled(), which will be true if the error handler is called regardless of whether or not the error handler β€œsmooths” the problem over by inserting replacement characters, doing nothing, or otherwise.

The overloads of this function increase the level of control you have with each passed argument. At the last overload with four arguments, the function attempts to work call some extension points or falls back to the base function call in this order:

  • The text_count_as_decoded(input, encoding, handler, state) extension point, if possible.

  • An internal, implementation-defined customization point.

  • The basic_count_as_decoded base function.

The base function call, basic_count_as_decoded, simply performs the core counting loop using the Lucky 7 design.

During the basic_count_as_decoded loop, if it detects that there is a preferable text_count_as_decoded_one, it will call that method as text_count_as_decoded_one(input, encoding, handler, state) inside of the loop rather than doing the core design.

Note

πŸ‘‰ This means that if you implement none of the extension points whatsoever, implementing the basic decode_one function on your Encoding Object type will guarantee a proper, working implementation.

Note

πŸ‘‰ If you need to call the β€œbasic” form of this function that takes no secret implementation shortcuts or user-defined extension points, then call basic_count_as_decoded directly. This can be useful to stop infinity loops when your extension points cannot handle certain inputs and thereby needs to β€œdelegate” to the basic case.


Functions

template<typename _Input, typename _Encoding, typename _ErrorHandler, typename _State>
constexpr auto basic_count_as_decoded(_Input &&__input, _Encoding &&__encoding, _ErrorHandler &&__error_handler, _State &__state)

Counts the number of code units that will result from attempting a decode operation.

Remark

This method does not call ADL extension points. It attempts a combination of implementation techniques to count code units, with a loop over the .decode call into an intermediate, unseen buffer being the most basic guaranteed implementation attempt.

Parameters:
  • __input – [in] The input range (of code units) to find out how many code points there are.

  • __encoding – [in] The encoding to count the input with.

  • __error_handler – [in] The error handler to invoke when an encode operation fails.

  • __state – [inout] The state that will be used to count code units.

Returns:

A ztd::text::count_result that includes information about how many code units are present, taking into account any invoked errors (like replacement from ztd::text::replacement_handler_t) and a reference to the provided __state.

template<typename _Input, typename _Encoding, typename _ErrorHandler, typename _State>
constexpr auto count_as_decoded(_Input &&__input, _Encoding &&__encoding, _ErrorHandler &&__error_handler, _State &__state)

Counts the number of code units that will result from attempting a decode operation.

Remark

This method will first check if an ADL Extension Point text_count_as_decoded is callable with the given arguments. If it is, then that method will be used to do the work after forwarding all four arguments to that function call. Otherwise, it defers to ztd::text::basic_count_as_decoded.

Parameters:
  • __input – [in] The input range (of code units) to find out how many code points there are.

  • __encoding – [in] The encoding to count the input with.

  • __error_handler – [in] The error handler to invoke when an encode operation fails.

  • __state – [inout] The state that will be used to count code units.

Returns:

A ztd::text::count_result that includes information about how many code units are present, taking into account any invoked errors (like replacement from ztd::text::replacement_handler_t) and a reference to the provided __state.

template<typename _Input, typename _Encoding, typename _ErrorHandler>
constexpr auto count_as_decoded(_Input &&__input, _Encoding &&__encoding, _ErrorHandler &&__error_handler)

Counts the number of code units that will result from attempting a decode operation.

Remark

Calls ztd::text::count_as_decoded(Input, Encoding, ErrorHandler, State) with an state that is created by ztd::text::make_decode_state(Encoding).

Parameters:
  • __input – [in] The input range (of code units) to find out how many code points there are.

  • __encoding – [in] The encoding to count the input with.

  • __error_handler – [in] The error handler to invoke when an encode operation fails.

Returns:

A ztd::text::stateless_count_result that includes information about how many code units are present, taking into account any invoked errors (like replacement from ztd::text::replacement_handler_t).

template<typename _Input, typename _Encoding>
constexpr auto count_as_decoded(_Input &&__input, _Encoding &&__encoding)

Counts the number of code units that will result from attempting a decode operation.

Remark

Calls ztd::text::count_as_decoded(Input, Encoding, ErrorHandler) with an error_handler that is similar to ztd::text::default_handler_t.

Parameters:
  • __input – [in] The input range (of code units) to find out how many code points there are.

  • __encoding – [in] The encoding to count the input with.

Returns:

A ztd::text::stateless_count_result that includes information about how many code units are present, taking into account any invoked errors (like replacement from ztd::text::replacement_handler_t).

template<typename _Input>
constexpr auto count_as_decoded(_Input &&__input)

Counts the number of code units that will result from attempting a decode operation.

Remark

Calls ztd::text::count_as_decoded(Input, Encoding) with an encoding that is derived from ztd::text::default_code_unit_encoding.

Parameters:

__input – [in] The input range (of code units) to find out how many code points there are.

Returns:

A ztd::text::stateless_count_result that includes information about how many code units are present, taking into account any invoked errors (like replacement from ztd::text::replacement_handler_t).