cppx-core
utf16-Generator.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
2 
3 #include <cppx-core/language/bit-level/bits_per_.hpp> // cppx::magnitude_bits_per_
4 #include <cppx-core/text/unicode/unicode-Code_point_generator.hpp> // cppx::unicode::Code_point_generator
5 #include <cppx-core/text/unicode/utf16-surrogate-pairs.hpp> // cppx::utf16::*
6 
7 #include <iterator> // std::(distance, next)
8 #include <functional> // std::invoke
9 
10 namespace cppx::utf16
11 {
12  CPPX_USE_STD( distance, invoke, ref, next );
13 
14  class Generator:
16  {
17  public:
18  template< class Out_iterator >
19  auto utf16_from_byte( const Byte value, const Out_iterator destination )
20  -> Out_iterator
21  {
23  CPPX_FAIL( "Not implemented yet" );
24  }
25 
26  template< class In_iterator, class Out_iterator >
28  const Span_<In_iterator> bytes_range,
29  const Out_iterator destination
30  ) -> Out_iterator
31  {
33  //using Out_value = Item_for_iterator_<Out_iterator>;
34 
35  Out_iterator current = destination;
36  const In_iterator beyond_bytes = bytes_range.beyond();
37  for( auto it = bytes_range.first(); it != beyond_bytes; )
38  {
39  const uint32_t code_point = code_point_from_bytes( in_out_ref( it ), beyond_bytes );
40  current = utf16::from_code_point( code_point, current );
41  }
42  return current;
43  }
44 
45  template< class In_iterator, class Out_iterator >
47  const In_iterator first,
48  const In_iterator beyond,
49  const Out_iterator destination
50  ) -> Out_iterator
51  {
53  return utf16_from_bytes( Span_( first, beyond ), destination );
54  }
55  };
56 } // namespace cppx::utf16
auto from_code_point(const uint32_t code_point, const Out_iterator destination) -> Out_iterator
constexpr int magnitude_bits_per_
The number of bits that determine the magnitude, i.e. the number of value representation bits minus a...
Definition: bits_per_.hpp:30
auto utf16_from_byte(const Byte value, const Out_iterator destination) -> Out_iterator
auto in_out_ref(Type &o) -> In_out_ref_< Type >
Definition: In_out_ref_.hpp:35
bits_per_ and magnitude_bits_per_, plus the for-readability constant bits_per_byte.
auto utf16_from_bytes(const In_iterator first, const In_iterator beyond, const Out_iterator destination) -> Out_iterator
auto next(P_< const char > p) -> P_< const char >
auto code_point_from_bytes(In_out_ref_< In_iterator > it_ref, const In_iterator beyond) -> uint32_t
unsigned char Byte
Default choice of byte type.
Definition: byte-types.hpp:19
typename std::iterator_traits< Iterator >::value_type Item_for_iterator_
Definition: type-traits.hpp:50
CPPX_USE_STD(basic_string, basic_string_view, string, string_view, u16string, wstring, iterator_traits, move, next)
#define CPPX_FAIL(...)
Definition: macro-fail.hpp:10
auto utf16_from_bytes(const Span_< In_iterator > bytes_range, const Out_iterator destination) -> Out_iterator