From dd685fb0bd6726038c863a69037cc30a7294ffcf Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 15 Nov 2021 10:40:42 +0100 Subject: Build w/ C++20 --- Makefile | 4 ++-- include/unicode.h | 24 +++++++++++++----------- src/test-unicode.cpp | 6 +++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 03bf1d1..f3f072f 100644 --- a/Makefile +++ b/Makefile @@ -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 -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 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> + template> 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> + template> 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 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 success_sets { }; // Error cases: throwing upon convert to all other types -std::vector> failure_strings_char8_t { +std::vector> 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("\xa4")}), std::invalid_argument); // € not available in ISO-8859-1 - BOOST_CHECK((unicode::convert("abc")) == std::u16string{u"abc"}); + BOOST_CHECK((unicode::convert(u8"abc")) == std::u16string{u"abc"}); BOOST_CHECK((unicode::convert(U"abc")) == std::u16string{u"abc"}); BOOST_CHECK((unicode::convert("abc")) == std::u16string{u"abc"}); @@ -385,7 +385,7 @@ BOOST_AUTO_TEST_CASE(convert) BOOST_CHECK((unicode::convert(u8"\u732b")) == std::wstring{L"\u732b"}); BOOST_CHECK((unicode::convert(u8"\U0001F63A")) == std::wstring{L"\U0001F63A"}); BOOST_CHECK((unicode::convert(L"\U0001F63A")) == std::u32string{U"\U0001F63A"}); - BOOST_CHECK((unicode::convert(L"\U0001F63A")) == std::string{u8"\U0001F63A"}); + BOOST_CHECK((unicode::convert(L"\U0001F63A")) == std::u8string{u8"\U0001F63A"}); BOOST_CHECK((unicode::convert(std::string{"äöü"})) == std::wstring{L"äöü"}); -- cgit v1.2.3