summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2021-12-30 16:39:59 +0100
committerRoland Reichwein <mail@reichwein.it>2021-12-30 16:39:59 +0100
commitc5b5aadd8ac8faeeb9e04076166df4d685633cf6 (patch)
treef0d4a1cee11be26ebfee616e96eeaf606d631fe4 /include
parent93efbaeef12f017bf72b3952f3b2a67ca9fec5de (diff)
Bugfix: Mapping to ISO-8859-15 was broken
Diffstat (limited to 'include')
-rw-r--r--include/unicode.h9
1 files 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<char32_t>(static_cast<uint8_t>(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<uint32_t>(value)));
s.push_back(it->second);
return *this;
}
@@ -775,7 +778,7 @@ namespace unicode {
template<typename From, typename To, std::enable_if_t<std::is_empty<From>::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<From, UTF<utf_iterator<typename From::value_type>, utf_back_insert_iterator<typename From::value_type>>> &&
std::is_same_v<To, UTF<utf_iterator<typename To::value_type>, utf_back_insert_iterator<typename To::value_type>>>) {