1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi"). 13 #include <c/assert.hpp> 20 CPPX_USE_STD( basic_string, basic_string_view, iterator_traits, exchange, move,
next,
string );
25 template<
class Out_iterator >
26 auto output_utf8(
const uint32_t code,
const Out_iterator destination )
29 using Out_code =
typename iterator_traits<Out_iterator>::value_type;
31 Out_iterator out = destination;
35 *out = static_cast<Out_code>( code ); ++out;
37 else if( code <= 0x7FF )
40 *out = static_cast<Out_code>( 0b11000000 | (code >> 6) ); ++out;
41 *out = static_cast<Out_code>( 0b10000000 | (code & 0x3F) ); ++out;
43 else if( code <= 0xFFFF )
46 *out = static_cast<Out_code>( 0b11100000 | (code >> 12) ); ++out;
47 *out = static_cast<Out_code>( 0b10000000 | ((code >> 6) & 0x3F) ); ++out;
48 *out = static_cast<Out_code>( 0b10000000 | (code & 0x3F) ); ++out;
53 *out = static_cast<Out_code>( 0b11110000 | (code >> 18) ); ++out;
54 *out = static_cast<Out_code>( 0b10000000 | ((code >> 12) & 0x3F) ); ++out;
55 *out = static_cast<Out_code>( 0b10000000 | ((code >> 6) & 0x3F) ); ++out;
56 *out = static_cast<Out_code>( 0b10000000 | (code & 0x3F) ); ++out;
65 uint32_t m_surrogate_1 = 0;
66 Size m_n_bad_chars = 0;
71 template<
class Out_iterator >
75 Out_iterator it = destination;
76 if( m_surrogate_1 != 0 )
81 const uint32_t first_value = exchange( m_surrogate_1, 0 );
82 const uint32_t second_value = code;
84 return impl::output_utf8( full_code, it );
105 return impl::output_utf8( code, it );
108 template<
class In_iterator,
class Out_iterator >
111 const Out_iterator destination
114 Out_iterator current = destination;
115 for(
const uint32_t code : range )
122 template<
class In_iterator,
class Out_iterator >
124 const In_iterator first,
125 const In_iterator beyond,
126 const Out_iterator destination
auto utf8_from_code(const uint32_t code, const Out_iterator destination) -> Out_iterator
A drop-in replacement for bool without implicit conversion from/to types other than bool.
CPPX_USE_STD(basic_string, basic_string_view, iterator_traits, move, next, string, string_view)
constexpr Range_< unsigned > range_of_pair_value_2(0xDC00, 0xDFFF)
auto n_bad_chars() const noexcept -> Size
auto utf8_from_codes(const Span_< In_iterator > range, const Out_iterator destination) -> Out_iterator
Truth is a drop-in replacement for bool without implicit conversion from/to types other than bool.
constexpr Range_< unsigned > range_of_pair_value_1(0xD800, 0xDBFF)
constexpr auto code_from_pair(const unsigned v1, const unsigned v2) noexcept -> uint32_t
auto utf8_from_codes(const In_iterator first, const In_iterator beyond, const Out_iterator destination) -> Out_iterator
Simple type builders Type_, P_, R_, Raw_array_ and Raw_array_of_.
auto next(P_< const char > p) -> P_< const char >
$items_of eases use of standard library functions, e.g. sort( $items_of( numbers ) ).
Signed_< size_t > Size
A Signed_ equivalent of size_t.
Macros for generating more concise and clear using statements, primarily $use_cppx and $use_std,...
Byte and Signed_byte, + std::byte support definitions as_number and as_std_byte.
auto contains(const Integer v) -> Truth
Signed Size and Index, plus unsigned equivalents Unsigned_size and Unsigned_index.