xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel > Class Template Reference

A convert that allows conversion from one string type to another. More...

#include <xentara/utils/string/convert.hpp>

Public Types

using InputChar = std::iter_value_t< InputIterator >
 The input character type.
 
using OutputChar = std::remove_cv_t< OutputCharT >
 

Public Member Functions

 Converter (InputIterator begin, InputSentinel end)
 Constructor.
 
 Converter (std::basic_string_view< InputChar > input)
 Constructor for converting a string view.
 
 Converter (InputIterator begin, InputSentinel end, std::in_place_type_t< OutputChar >)
 Constructor with a type marker for the output type.
 
 Converter (std::basic_string_view< InputChar > input, std::in_place_type_t< OutputChar >)
 Constructor for converting a string view with a type marker for the output type.
 
template<std::output_iterator< OutputCharT > OutputIterator, std::sentinel_for< OutputIterator > OutputSentinel = std::unreachable_sentinel_t>
auto convert (OutputIterator output, OutputSentinel outputEnd=std::unreachable_sentinel) -> OutputIterator
 Converts a chunk of a string using an output iterator.
 
auto isDone () const -> bool
 Determines whether the input sequence has been converted completely.
 

Static Public Member Functions

static auto convertedSize (InputIterator begin, InputSentinel end) -> std::size_t
 Calculates the size of a converted character sequence.
 
static constexpr auto isNoop () -> bool
 Determines whether the conversion is a NOOP.
 

Detailed Description

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
requires tools::CharType<std::iter_value_t<InputIterator>>
class xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >

A convert that allows conversion from one string type to another.

This converter preserves state across calls of convert() to allow you to allocate more output data

Member Typedef Documentation

◆ InputChar

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
using xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >::InputChar = std::iter_value_t<InputIterator>

The input character type.

◆ OutputChar

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
using xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >::OutputChar = std::remove_cv_t<OutputCharT>

Constructor & Destructor Documentation

◆ Converter() [1/4]

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >::Converter ( InputIterator  begin,
InputSentinel  end 
)

Constructor.

Parameters
beginThe beginning of the input sequence
endThe end of the input sequence

◆ Converter() [2/4]

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >::Converter ( std::basic_string_view< InputChar input)

Constructor for converting a string view.

Parameters
inputThe input sequence

◆ Converter() [3/4]

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >::Converter ( InputIterator  begin,
InputSentinel  end,
std::in_place_type_t< OutputChar  
)

Constructor with a type marker for the output type.

Parameters
beginThe beginning of the input sequence
endThe end of the input sequence

◆ Converter() [4/4]

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >::Converter ( std::basic_string_view< InputChar input,
std::in_place_type_t< OutputChar  
)

Constructor for converting a string view with a type marker for the output type.

Parameters
inputThe input sequence

Member Function Documentation

◆ convert()

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
template<std::output_iterator< OutputCharT > OutputIterator, std::sentinel_for< OutputIterator > OutputSentinel = std::unreachable_sentinel_t>
auto xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >::convert ( OutputIterator  output,
OutputSentinel  outputEnd = std::unreachable_sentinel 
) -> OutputIterator

Converts a chunk of a string using an output iterator.

This function converts as many characters from the input sequence as can be written to an output iterator. Illegal code points (high and low surrogates, and code points higher than U+10FFFF) and non-decodable input values are replaced by the replacement character.

You can check whether the conversion has completed by calling isDone().

Note
If the input and output types have the same encoding, the data is copied as-is, without checking the validity. This means you cannot use this function to correct corrupt Unicode data.
Parameters
outputAn output iterator for the output sequence
outputEndA sentinel to mark the end of the output sequence
Returns
Returns an iterator to the position beyond the last character written to the output sequence

◆ convertedSize()

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
static auto xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >::convertedSize ( InputIterator  begin,
InputSentinel  end 
) -> std::size_t
static

Calculates the size of a converted character sequence.

◆ isDone()

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
auto xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >::isDone ( ) const -> bool

Determines whether the input sequence has been converted completely.

Returns
Returns true if all characters in the input sequence have been converted an written to the output sequence. Returns false if convert() needs to be called again with more buffer space.

◆ isNoop()

template<tools::CharType OutputCharT, std::input_iterator InputIterator, std::sentinel_for< InputIterator > InputSentinel>
static constexpr auto xentara::utils::string::Converter< OutputCharT, InputIterator, InputSentinel >::isNoop ( ) -> bool
staticconstexpr

Determines whether the conversion is a NOOP.

Returns
Returns true if the input and output encoding are the same.