diff options
author | Roland Reichwein <mail@reichwein.it> | 2021-11-15 10:40:42 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2021-11-15 10:40:42 +0100 |
commit | dd685fb0bd6726038c863a69037cc30a7294ffcf (patch) | |
tree | b0716227f779bf048d828bd8d38ca0fa712d1af8 | |
parent | 089ebb0f38ff3b26397a1d5685a9bf8c69af1fdb (diff) |
Build w/ C++20
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | include/unicode.h | 24 | ||||
-rw-r--r-- | src/test-unicode.cpp | 6 |
3 files changed, 18 insertions, 16 deletions
@@ -14,8 +14,8 @@ CXX=clang++-11 endif # boost is buggy for C++20: error: static_assert failed due to requirement 'detail::is_endian_reversible_inplace<char8_t> -STANDARD=c++17 -#STANDARD=c++20 +#STANDARD=c++17 +STANDARD=c++20 ifeq ($(CXXFLAGS),) CXXFLAGS=-O0 -g -D_DEBUG diff --git a/include/unicode.h b/include/unicode.h index 502ec16..33b3199 100644 --- a/include/unicode.h +++ b/include/unicode.h @@ -19,8 +19,10 @@ #ifdef __cpp_char8_t // char8_t available typedef char8_t utf8_t; + typedef char iso_t; #else typedef char utf8_t; + typedef char iso_t; #endif namespace unicode { @@ -353,10 +355,10 @@ namespace unicode::detail { typedef std::unordered_map<char32_t, utf8_t> iso_map_type_reverse; // ISO-8859-1 is lower 8-bit of Unicode, so no exceptions necessary - iso_map_type iso_8859_1_map; + static inline iso_map_type iso_8859_1_map; // ISO-8859-15 is lower 8-bit of Unicode, except for: - iso_map_type iso_8859_15_map { + static inline iso_map_type iso_8859_15_map { { '\xA4', U'\u20AC' }, // € { '\xA6', U'\u0160' }, // Š { '\xA8', U'\u0161' }, // š @@ -367,7 +369,7 @@ namespace unicode::detail { { '\xBE', U'\u0178' }, // Ÿ }; - iso_map_type_reverse reverse_iso_map(const iso_map_type& map) { + inline iso_map_type_reverse reverse_iso_map(const iso_map_type& map) { iso_map_type_reverse result; std::for_each(map.cbegin(), map.cend(), [&](const iso_map_type::value_type& pair) @@ -377,8 +379,8 @@ namespace unicode::detail { return result; } - iso_map_type_reverse iso_8859_15_map_reverse { reverse_iso_map(iso_8859_15_map) }; - iso_map_type_reverse iso_8859_1_map_reverse { reverse_iso_map(iso_8859_1_map) }; + static inline iso_map_type_reverse iso_8859_15_map_reverse { reverse_iso_map(iso_8859_15_map) }; + static inline iso_map_type_reverse iso_8859_1_map_reverse { reverse_iso_map(iso_8859_1_map) }; } // namespace unicode::detail @@ -386,9 +388,9 @@ namespace unicode { using namespace detail; - template<unicode::detail::iso_map_type& Map=iso_8859_1_map, typename Container=std::basic_string<utf8_t>> + template<unicode::detail::iso_map_type& Map=iso_8859_1_map, typename Container=std::basic_string<iso_t>> struct iso_iterator { - typedef utf8_t input_type; + typedef iso_t input_type; typedef char32_t value_type; typedef char32_t& reference; typedef char32_t* pointer; @@ -414,7 +416,7 @@ namespace unicode { // return reference? value_type operator*() { - utf8_t value{*m_it}; + input_type value{*m_it}; if constexpr(std::addressof(Map) != std::addressof(iso_8859_1_map)) // mapping of 128 <= x <= 255 needed { @@ -429,12 +431,12 @@ namespace unicode { iterator m_it; }; - template<unicode::detail::iso_map_type_reverse& Map=iso_8859_1_map_reverse, typename Container=std::basic_string<utf8_t>> + template<unicode::detail::iso_map_type_reverse& Map=iso_8859_1_map_reverse, typename Container=std::basic_string<iso_t>> struct iso_back_insert_iterator { typedef iso_back_insert_iterator& reference; typedef iso_back_insert_iterator* pointer; typedef size_t difference_type; - typedef utf8_t value_type; + typedef iso_t value_type; typedef std::output_iterator_tag iterator_category; typedef Container string_type; @@ -486,7 +488,7 @@ namespace unicode { template<typename InputIt, typename OutputIt> struct ISO_8859 { - typedef utf8_t value_type; + typedef iso_t value_type; typedef typename InputIt::string_type string_type; static InputIt begin(const typename InputIt::string_type& s) diff --git a/src/test-unicode.cpp b/src/test-unicode.cpp index 65ab5a2..9c68c59 100644 --- a/src/test-unicode.cpp +++ b/src/test-unicode.cpp @@ -37,7 +37,7 @@ std::vector<types_collection_type> success_sets { }; // Error cases: throwing upon convert to all other types -std::vector<std::basic_string<utf8_t>> failure_strings_char8_t { +std::vector<std::basic_string<iso_t>> failure_strings_char8_t { // using u8"" here doesn't work on MSVC "\x80", // utf-8 continuation byte "\x81", // utf-8 continuation byte @@ -364,7 +364,7 @@ BOOST_AUTO_TEST_CASE(convert) BOOST_CHECK_THROW(((void)std::string{unicode::convert<unicode::ISO_8859_15,unicode::ISO_8859_1>("\xa4")}), std::invalid_argument); // € not available in ISO-8859-1 - BOOST_CHECK((unicode::convert<unicode::UTF_8,unicode::UTF_16>("abc")) == std::u16string{u"abc"}); + BOOST_CHECK((unicode::convert<unicode::UTF_8,unicode::UTF_16>(u8"abc")) == std::u16string{u"abc"}); BOOST_CHECK((unicode::convert<unicode::UTF_32,unicode::UTF_16>(U"abc")) == std::u16string{u"abc"}); BOOST_CHECK((unicode::convert<utf8_t,char16_t>("abc")) == std::u16string{u"abc"}); @@ -385,7 +385,7 @@ BOOST_AUTO_TEST_CASE(convert) BOOST_CHECK((unicode::convert<char, wchar_t>(u8"\u732b")) == std::wstring{L"\u732b"}); BOOST_CHECK((unicode::convert<char, wchar_t>(u8"\U0001F63A")) == std::wstring{L"\U0001F63A"}); BOOST_CHECK((unicode::convert<wchar_t, char32_t>(L"\U0001F63A")) == std::u32string{U"\U0001F63A"}); - BOOST_CHECK((unicode::convert<wchar_t, char>(L"\U0001F63A")) == std::string{u8"\U0001F63A"}); + BOOST_CHECK((unicode::convert<wchar_t, utf8_t>(L"\U0001F63A")) == std::u8string{u8"\U0001F63A"}); BOOST_CHECK((unicode::convert<std::string, std::wstring>(std::string{"äöü"})) == std::wstring{L"äöü"}); |