encode_view¶
The encode_view
class provides a one-by-one view of the stored range’s code points as the desired encoding’s code units. Dereferencing the iterators returns a single code_unit
value corresponding to the desired encoding’s transformation of the internal code points.
The range-based classes are excellent ways to walk over units of information in a low-memory environment, as they only store the minimum amount of data necessary to perform their operations on the fly. This reduces the speed but is fine for one-at-a-time encoding operations. To encode eagerly and in bulk, see the encode functions.
-
template<typename _Encoding, typename _Range = ::std::basic_string_view<code_point_t<_Encoding>>, typename _ErrorHandler = default_handler_t, typename _State = encode_state_t<_Encoding>>
class ztd::text::encode_view¶ A view over a range of code points, presenting the code points as code units. Uses the
_Encoding
specified to do so.- Remark
The view presents code units one at a time, regardless of how many code units are output by one decode operation. This means if, for example, one (1) UTF-32 code point becomes four (4) UTF-8 code units, it will present each code unit one at a time. If you are looking to explicitly know what a single encode operation maps into as far as number of code points to code units (and vice-versa), you will have to use lower-level interfaces.
- tparam _Encoding
The encoding to read the underlying range of code points as.
- tparam _Range
The range of input that will be fed into the _FromEncoding’s decode operation.
- tparam _ErrorHandler
The error handler for any encode-step failures.
- tparam _State
The state type to use for the encode operations to intermediate code points.
Public Types
-
using iterator = encode_iterator<_Encoding, _StoredRange, _ErrorHandler, _State>¶
The iterator type for this view.
-
using sentinel = encode_sentinel_t¶
The sentinel type for this view.
-
using error_handler_type = _ErrorHandler¶
The error handler when an encode operation fails.
-
using state_type = encode_state_t<encoding_type>¶
The state type used for encode operations.
Public Functions
-
constexpr encode_view() = default¶
Default constructor. Defaulted.
-
constexpr encode_view(const encode_view&) = default¶
Copy constructor. Defaulted.
-
constexpr encode_view(encode_view&&) = default¶
Move constructor. Defaulted.
-
template<typename _ArgRange, ::std::enable_if_t<!::std::is_same_v<remove_cvref_t<_ArgRange>, encode_view> && !::std::is_same_v<remove_cvref_t<_ArgRange>, iterator>>* = nullptr>
inline constexpr encode_view(_ArgRange &&__range) noexcept(::std::is_nothrow_constructible_v<iterator, _ArgRange>)¶ Constructs an encode_view from the underlying range.
- Remark
the stored encoding, error handler, and state type are default-constructed.
- Parameters
__range – [in] The input range to wrap and iterate over.
-
inline constexpr encode_view(range_type __range, encoding_type __encoding) noexcept(::std::is_nothrow_constructible_v<iterator, range_type, encoding_type>)¶
Constructs an encode_view from the underlying range.
- Parameters
__range – [in] The input range to wrap and iterate over.
__encoding – [in] The encoding object to call
.encode
or equivalent functionality on.
-
inline constexpr encode_view(range_type __range, encoding_type __encoding, error_handler_type __error_handler) noexcept(::std::is_nothrow_constructible_v<iterator, range_type, encoding_type, error_handler_type>)¶
Constructs an encode_view from the underlying range.
- Parameters
__range – [in] The input range to wrap and iterate over.
__encoding – [in] The encoding object to call
.encode
or equivalent functionality on.__error_handler – [in] A previously-made encode_view iterator.
-
inline constexpr encode_view(range_type __range, encoding_type __encoding, error_handler_type __error_handler, state_type __state) noexcept(::std::is_nothrow_constructible_v<iterator, range_type, encoding_type, error_handler_type, state_type>)¶
Constructs an encode_view from the underlying range.
- Parameters
__range – [in] The input range to wrap and iterate over.
__encoding – [in] The encoding object to call
.encode
or equivalent functionality on.__error_handler – [in] A previously-made encode_view iterator.
__state – [in] The state to user for the encode operation.
-
inline constexpr encode_view(iterator __it) noexcept(::std::is_nothrow_move_constructible_v<iterator>)¶
Constructs an encoding_view from one of its iterators, reconstituting the range.
- Parameters
__it – [in] A previously-made encode_view iterator.
-
constexpr encode_view &operator=(const encode_view&) = default¶
Copy assignment operator. Defaulted.
-
constexpr encode_view &operator=(encode_view&&) = default¶
Move assignment operator. Defaulted.
-
inline constexpr iterator begin() & noexcept¶
The beginning of the range. Uses a sentinel type and not a special iterator.
-
inline constexpr iterator begin() const & noexcept¶
The beginning of the range. Uses a sentinel type and not a special iterator.