9070 decoded_result<It> dr;
9073 dr.error = error_code::sequence_too_short;
9077 unsigned char b0 = *it;
9078 std::size_t
length = unicode_detail::sequence_length(b0);
9081 dr.codepoint =
static_cast<char32_t
>(b0);
9082 dr.error = error_code::ok;
9088 auto is_invalid = [](
unsigned char b) {
return b == 0xC0 || b == 0xC1 || b > 0xF4; };
9089 auto is_continuation = [](
unsigned char b) {
9090 return (b & unicode_detail::continuation_mask) == unicode_detail::continuation_signature;
9093 if (is_invalid(b0) || is_continuation(b0)) {
9094 dr.error = error_code::invalid_code_unit;
9100 std::array<unsigned char, 4> b;
9102 for (std::size_t i = 1; i < length; ++i) {
9104 if (!is_continuation(b[i])) {
9105 dr.error = error_code::invalid_code_unit;
9115 decoded = unicode_detail::decode(b[0], b[1]);
9118 decoded = unicode_detail::decode(b[0], b[1], b[2]);
9121 decoded = unicode_detail::decode(b[0], b[1], b[2], b[3]);
9125 auto is_overlong = [](char32_t u, std::size_t bytes) {
9126 return u <= unicode_detail::last_1byte_value
9127 || (u <= unicode_detail::last_2byte_value && bytes > 2)
9128 || (u <= unicode_detail::last_3byte_value && bytes > 3);
9130 if (is_overlong(decoded, length)) {
9131 dr.error = error_code::overlong_sequence;
9134 if (unicode_detail::is_surrogate(decoded) || decoded > unicode_detail::last_code_point) {
9135 dr.error = error_code::invalid_code_point;
9140 dr.codepoint = decoded;
9141 dr.error = error_code::ok;