From c5b5aadd8ac8faeeb9e04076166df4d685633cf6 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Thu, 30 Dec 2021 16:39:59 +0100 Subject: Bugfix: Mapping to ISO-8859-15 was broken --- include/unicode.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/unicode.h b/include/unicode.h index 1e19066..1190292 100644 --- a/include/unicode.h +++ b/include/unicode.h @@ -448,6 +448,7 @@ namespace unicode::detail { [&](const iso_map_type::value_type& pair) { result.emplace(pair.second, pair.first); + result.emplace(static_cast(static_cast(pair.first)), 0); // map invalid characters to a known non-mapped value as marker }); return result; } @@ -491,7 +492,7 @@ namespace unicode { { value_type value{*m_it}; - if constexpr(std::addressof(Map) != std::addressof(iso_8859_1_map)) // mapping of 128 <= x <= 255 needed + if constexpr(std::addressof(Map) != std::addressof(iso_8859_1_map)) // mapping of 128 <= x <= 255 if needed { auto it{Map.find(value)}; if (it != Map.end()) @@ -549,10 +550,12 @@ namespace unicode { reference operator=(const internal_type& value) { - if constexpr(std::addressof(Map) != std::addressof(iso_8859_1_map_reverse)) // mapping of 128 <= x <= 255 needed + if constexpr(std::addressof(Map) != std::addressof(iso_8859_1_map_reverse)) // mapping back to 128 <= x <= 255 if needed { auto it{Map.find(value)}; if (it != Map.end()) { + if (it->second == 0) // marker for non-mappable character found + throw std::invalid_argument("Bad Unicode value to map to ISO 8859-15: "s + std::to_string(static_cast(value))); s.push_back(it->second); return *this; } @@ -775,7 +778,7 @@ namespace unicode { template::value, bool> = true> typename To::string_type convert(const typename From::string_type& s) { - // if input type == output type, only validate and return input, is appropriate + // if input type == output type, only validate and return input, if appropriate if constexpr(sizeof(typename From::value_type) == sizeof(typename To::value_type) && std::is_same_v, utf_back_insert_iterator>> && std::is_same_v, utf_back_insert_iterator>>) { -- cgit v1.2.3