From 23c31aef916dbfd17774a80258676a963426a698 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 25 Dec 2021 20:20:02 +0100 Subject: Consistent use of internal_type --- include/unicode.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/include/unicode.h b/include/unicode.h index 8e120ad..3d6477c 100644 --- a/include/unicode.h +++ b/include/unicode.h @@ -228,6 +228,7 @@ namespace unicode::detail { static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4); typedef T value_type; + typedef char32_t internal_type; typedef Container string_type; typedef utf_back_insert_iterator& reference; typedef utf_back_insert_iterator* pointer; @@ -258,14 +259,14 @@ namespace unicode::detail { // n is number of UTF-8 bytes in sequence template - inline static value_type byte0_of(char32_t value) + inline static value_type byte0_of(internal_type value) { return (value >> 6 * (n - 1)) | (0xFF << (8 - n)); } // n is index of 6-bit groups, counting from bit 0 template - inline static value_type trailing_byte(char32_t value) + inline static value_type trailing_byte(internal_type value) { return ((value >> n * 6) & 0b111111) | 0b10000000; } @@ -273,7 +274,7 @@ namespace unicode::detail { // calculate UTF-8 sequence byte for m >= 2 bytes sequences (i.e. non-ASCII) // assume value to be valid Unicode value for given byte position template - inline static value_type byte_n_of_m(char32_t value) + inline static value_type byte_n_of_m(internal_type value) { if constexpr (n == 0) return byte0_of(value); @@ -303,7 +304,7 @@ namespace unicode::detail { } template::type = true> - inline void append_utf(const char32_t& value) + inline void append_utf(const internal_type& value) { if (value < 0x80) { // 1 byte append(static_cast(value)); @@ -318,24 +319,24 @@ namespace unicode::detail { } template::type = true> - inline void append_utf(const char32_t& value) + inline void append_utf(const internal_type& value) { if (value <= 0xFFFF) { // expect value to be already valid Unicode values (checked in input iterator) append(static_cast(value)); } else { - char32_t value_reduced{value - 0x10000}; + internal_type value_reduced{value - 0x10000}; append(static_cast((value_reduced >> 10) + 0xD800), static_cast((value_reduced & 0x3FF) + 0xDC00)); } } template::type = true> - inline void append_utf(const char32_t& value) + inline void append_utf(const internal_type& value) { // expect value to be already valid Unicode values (checked in input iterator) append(static_cast(value)); } - reference operator=(const char32_t& value) + reference operator=(const internal_type& value) { append_utf(value); return *this; @@ -442,6 +443,7 @@ namespace unicode { typedef iso_back_insert_iterator* pointer; typedef size_t difference_type; typedef iso_t value_type; + typedef char32_t internal_type; typedef std::output_iterator_tag iterator_category; typedef Container string_type; @@ -467,7 +469,7 @@ namespace unicode { return *this; } - reference operator=(const char32_t& value) + reference operator=(const internal_type& value) { if constexpr(std::addressof(Map) != std::addressof(iso_8859_1_map_reverse)) // mapping of 128 <= x <= 255 needed { -- cgit v1.2.3