summaryrefslogtreecommitdiffhomepage
path: root/include/unicode/utf.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/unicode/utf.h')
-rw-r--r--include/unicode/utf.h29
1 files changed, 16 insertions, 13 deletions
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)