summaryrefslogtreecommitdiffhomepage
path: root/include/unicode
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2022-01-01 21:02:15 +0100
committerRoland Reichwein <mail@reichwein.it>2022-01-01 21:02:15 +0100
commitc969cddf87a2c6d2eb74353f3115a70d166136e5 (patch)
tree2f1aa414cd37a41de064faf6e4121107648d66b2 /include/unicode
parent52d4375b10d920a59f1309c272a2e525feb1c25d (diff)
Use own type traits
Diffstat (limited to 'include/unicode')
-rw-r--r--include/unicode/type_traits.h2
-rw-r--r--include/unicode/utf.h29
-rw-r--r--include/unicode/utf_fwd.h23
3 files changed, 40 insertions, 14 deletions
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 <string>
#include <type_traits>
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 <list>
#include <string>
#include <stdexcept>
@@ -37,7 +40,7 @@ namespace unicode::detail {
(... && is_utf8_followup_byte(bytes)); // left fold for linear evaluation from left to right
}
- template<typename T, typename std::enable_if_t<(sizeof(T) == 1), bool> = true>
+ template<typename T, typename std::enable_if_t<is_utf_8_v<T>, bool> = true>
inline bool validate_utf(const std::basic_string<T>& s)
{
int i{};
@@ -78,7 +81,7 @@ namespace unicode::detail {
}
}
- template<typename T, typename std::enable_if_t<(sizeof(T) == 2), bool> = true>
+ template<typename T, typename std::enable_if_t<is_utf_16_v<T>, bool> = true>
inline bool validate_utf(const std::basic_string<T>& s)
{
int i{};
@@ -95,7 +98,7 @@ namespace unicode::detail {
return true;
}
- template<typename T, typename std::enable_if_t<(sizeof(T) == 4), bool> = true>
+ template<typename T, typename std::enable_if_t<is_utf_32_v<T>, bool> = true>
inline bool validate_utf(const std::basic_string<T>& s)
{
for (auto i: s)
@@ -135,10 +138,10 @@ namespace unicode::detail {
return decode_utf8_leading_byte<sequence_length>(b) | decode_utf8_followup_byte(bytes...);
}
- template<typename T, typename Container=std::basic_string<T>>
+ template<typename T, typename Container>
struct utf_iterator
{
- static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4);
+ static_assert(is_utf_8_v<T> || is_utf_16_v<T> || is_utf_32_v<T>);
typedef T value_type;
typedef char32_t internal_type;
@@ -199,13 +202,13 @@ namespace unicode::detail {
}
}
- template<class X = value_type, typename std::enable_if_t<(sizeof(X) == 1), bool> = true>
+ template<class X = value_type, typename std::enable_if_t<is_utf_8_v<X>, bool> = true>
inline internal_type calculate_value()
{
return calculate_utf8_value(static_cast<utf8_t>(get_code_unit<0>()));
}
- template<class X = value_type, typename std::enable_if_t<(sizeof(X) == 2), bool> = true>
+ template<class X = value_type, typename std::enable_if_t<is_utf_16_v<X>, bool> = true>
inline internal_type calculate_value()
{
char16_t unit0 {static_cast<char16_t>(get_code_unit<0>())};
@@ -226,7 +229,7 @@ namespace unicode::detail {
}
}
- template<class X = value_type, typename std::enable_if_t<(sizeof(X) == 4), bool> = true>
+ template<class X = value_type, typename std::enable_if_t<is_utf_32_v<X>, bool> = true>
inline internal_type calculate_value()
{
internal_type result {static_cast<internal_type>(get_code_unit<0>())};
@@ -296,10 +299,10 @@ namespace unicode::detail {
return utf8_trailing_byte<m - n - 1, From, To>(value);
}
- template<typename T, typename Container=std::basic_string<T>>
+ template<typename T, typename Container>
struct utf_back_insert_iterator
{
- static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4);
+ static_assert(is_utf_8_v<T> || is_utf_16_v<T> || is_utf_32_v<T>);
typedef T value_type;
typedef char32_t internal_type;
@@ -341,7 +344,7 @@ namespace unicode::detail {
}
}
- template<class X = value_type, typename std::enable_if_t<(sizeof(X) == 1), bool> = true>
+ template<class X = value_type, typename std::enable_if_t<is_utf_8_v<X>, bool> = true>
inline void append_utf(const internal_type& value)
{
using Y = internal_type;
@@ -357,7 +360,7 @@ namespace unicode::detail {
}
}
- template<class X = value_type, typename std::enable_if_t<(sizeof(X) == 2), bool> = true>
+ template<class X = value_type, typename std::enable_if_t<is_utf_16_v<X>, 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<class X = value_type, typename std::enable_if_t<(sizeof(X) == 4), bool> = true>
+ template<class X = value_type, typename std::enable_if_t<is_utf_32_v<X>, 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 <string>
+
+namespace unicode::detail {
+
+ template<typename T, typename Container=std::basic_string<T>>
+ struct utf_iterator;
+
+ template<typename T, typename Container=std::basic_string<T>>
+ struct utf_back_insert_iterator;
+
+} // namespace unicode::detail
+
+namespace unicode {
+
+ template<typename InputIt, typename OutputIt>
+ struct UTF;
+
+} // namespace unicode
+