From c969cddf87a2c6d2eb74353f3115a70d166136e5 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 1 Jan 2022 21:02:15 +0100 Subject: Use own type traits --- include/unicode/type_traits.h | 2 +- include/unicode/utf.h | 29 ++++++++++++++++------------- include/unicode/utf_fwd.h | 23 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 include/unicode/utf_fwd.h (limited to 'include/unicode') diff --git a/include/unicode/type_traits.h b/include/unicode/type_traits.h index 3ee1d82..c3507e7 100644 --- a/include/unicode/type_traits.h +++ b/include/unicode/type_traits.h @@ -1,6 +1,6 @@ #pragma once -#include "utf.h" +#include "utf_fwd.h" #include #include diff --git a/include/unicode/utf.h b/include/unicode/utf.h index dd504a7..81e8f2b 100644 --- a/include/unicode/utf.h +++ b/include/unicode/utf.h @@ -1,5 +1,8 @@ #pragma once +#include "utf_fwd.h" +#include "type_traits.h" + #include #include #include @@ -37,7 +40,7 @@ namespace unicode::detail { (... && is_utf8_followup_byte(bytes)); // left fold for linear evaluation from left to right } - template = true> + template, bool> = true> inline bool validate_utf(const std::basic_string& s) { int i{}; @@ -78,7 +81,7 @@ namespace unicode::detail { } } - template = true> + template, bool> = true> inline bool validate_utf(const std::basic_string& s) { int i{}; @@ -95,7 +98,7 @@ namespace unicode::detail { return true; } - template = true> + template, bool> = true> inline bool validate_utf(const std::basic_string& s) { for (auto i: s) @@ -135,10 +138,10 @@ namespace unicode::detail { return decode_utf8_leading_byte(b) | decode_utf8_followup_byte(bytes...); } - template> + template struct utf_iterator { - static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4); + static_assert(is_utf_8_v || is_utf_16_v || is_utf_32_v); typedef T value_type; typedef char32_t internal_type; @@ -199,13 +202,13 @@ namespace unicode::detail { } } - template = true> + template, bool> = true> inline internal_type calculate_value() { return calculate_utf8_value(static_cast(get_code_unit<0>())); } - template = true> + template, bool> = true> inline internal_type calculate_value() { char16_t unit0 {static_cast(get_code_unit<0>())}; @@ -226,7 +229,7 @@ namespace unicode::detail { } } - template = true> + template, bool> = true> inline internal_type calculate_value() { internal_type result {static_cast(get_code_unit<0>())}; @@ -296,10 +299,10 @@ namespace unicode::detail { return utf8_trailing_byte(value); } - template> + template struct utf_back_insert_iterator { - static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4); + static_assert(is_utf_8_v || is_utf_16_v || is_utf_32_v); typedef T value_type; typedef char32_t internal_type; @@ -341,7 +344,7 @@ namespace unicode::detail { } } - template = true> + template, bool> = true> inline void append_utf(const internal_type& value) { using Y = internal_type; @@ -357,7 +360,7 @@ namespace unicode::detail { } } - template = true> + template, bool> = true> inline void append_utf(const internal_type& value) { if (value <= 0xFFFF) { // expect value to be already valid Unicode values (checked in input iterator) @@ -368,7 +371,7 @@ namespace unicode::detail { } } - template = true> + template, bool> = true> inline void append_utf(const internal_type& value) { // expect value to be already valid Unicode values (checked in input iterator) diff --git a/include/unicode/utf_fwd.h b/include/unicode/utf_fwd.h new file mode 100644 index 0000000..f3f6c52 --- /dev/null +++ b/include/unicode/utf_fwd.h @@ -0,0 +1,23 @@ +#pragma once + +// Forward declarations + +#include + +namespace unicode::detail { + + template> + struct utf_iterator; + + template> + struct utf_back_insert_iterator; + +} // namespace unicode::detail + +namespace unicode { + + template + struct UTF; + +} // namespace unicode + -- cgit v1.2.3