diff options
Diffstat (limited to 'include/unicode.h')
-rw-r--r-- | include/unicode.h | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/include/unicode.h b/include/unicode.h index d6f8e51..171496e 100644 --- a/include/unicode.h +++ b/include/unicode.h @@ -12,6 +12,7 @@ #include <memory> #include <stdexcept> #include <string> +#include <type_traits> #include <unordered_map> #ifdef __cpp_char8_t @@ -526,7 +527,7 @@ namespace unicode { typedef UTF<utf_iterator<char32_t>, utf_back_insert_iterator<char32_t>> UTF_32; // From and To are facets - template<typename From, typename To> + template<typename From, typename To, std::enable_if_t<std::is_empty<From>::value && std::is_empty<To>::value, bool> = true> std::basic_string<typename To::value_type> convert(const std::basic_string<typename From::value_type>& s) { std::basic_string<typename To::value_type> result; @@ -561,7 +562,9 @@ namespace unicode { }; // From and To are from: utf8_t, char16_t and char32_t - template<typename From, typename To> + template<typename From, typename To, + std::enable_if_t<std::is_trivial<From>::value && std::is_trivial<To>::value, bool> = true + > std::basic_string<To> convert(const std::basic_string<From>& s) { typedef UTF<utf_iterator<From>, utf_back_insert_iterator<To>> UTF_Trait; @@ -573,6 +576,20 @@ namespace unicode { return result; } + template<typename FromContainer, typename ToContainer, + std::enable_if_t<!std::is_empty<FromContainer>::value && !std::is_empty<ToContainer>::value, bool> = true + > + ToContainer convert(const FromContainer& s) + { + typedef UTF<utf_iterator<typename FromContainer::value_type>, utf_back_insert_iterator<typename ToContainer::value_type>> UTF_Trait; + + ToContainer result; + + std::copy(UTF_Trait::begin(s), UTF_Trait::end(s), UTF_Trait::back_inserter(result)); + + return result; + } + // basic type version template<typename T> bool is_valid_utf(const std::basic_string<T>& s) |