From e24a0d5d371d0916dbfb375d3ea404f7e6237c74 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 18 Dec 2021 15:08:06 +0100 Subject: Code cleanup --- include/unicode.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/unicode.h b/include/unicode.h index 277c4de..6b6f21a 100644 --- a/include/unicode.h +++ b/include/unicode.h @@ -199,14 +199,14 @@ namespace unicode::detail { // set value member void calculate_value() { + static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4); + if constexpr(sizeof(T) == 1) { calculate_value_utf8(); } else if constexpr (sizeof(T) == 2) { calculate_value_utf16(); } else if constexpr (sizeof(T) == 4) { calculate_value_utf32(); - } else { - throw std::runtime_error("Invalid character size: "s + std::to_string(sizeof(T))); } } @@ -334,14 +334,14 @@ namespace unicode::detail { reference operator=(const char32_t& value) { + static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4); + if constexpr(sizeof(T) == 1) { append_utf8(value); } else if constexpr(sizeof(T) == 2) { append_utf16(value); } else if constexpr(sizeof(T) == 4) { append_utf32(value); - } else { - throw std::runtime_error("Invalid type size: "s + std::to_string(sizeof(T))); } return *this; } @@ -473,7 +473,7 @@ namespace unicode { } if (value > 255) - throw std::invalid_argument("Bad Unicode value above 255: "s + std::to_string(static_cast(value))); + throw std::invalid_argument("Bad ISO 8859 value above 255: "s + std::to_string(static_cast(value))); s.push_back(static_cast(value)); return *this; -- cgit v1.2.3