From 5e1fab3590abf7cf8bcb9ce8c66ba0f785689178 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 2 Oct 2017 15:40:54 +1100 Subject: [PATCH] utf8: use mask test object for continuation ops --- utf8.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utf8.cpp b/utf8.cpp index d66e7e9e..dbdb6a21 100644 --- a/utf8.cpp +++ b/utf8.cpp @@ -111,15 +111,16 @@ util::utf8::decode (view src) codepoint_t shift = 0; // check every following data byte has the appropriate prefix + constexpr auto CONTINUATION = "0b10xxxxxx"_test; for (int i = 1; i <= len; ++i) { - if ((std::to_integer (cursor[i]) & 0b11'000000u) != 0b10'000000u) + if (!CONTINUATION.valid (std::to_integer (cursor[i]))) throw malformed_error {}; } switch (len) { - case 3: accum |= (std::to_integer (cursor[3]) & 0b00111111u) << (shift++ * 6u); - case 2: accum |= (std::to_integer (cursor[2]) & 0b00111111u) << (shift++ * 6u); - case 1: accum |= (std::to_integer (cursor[1]) & 0b00111111u) << (shift++ * 6u); + case 3: accum |= CONTINUATION.value (std::to_integer (cursor[3])) << (shift++ * 6u); + case 2: accum |= CONTINUATION.value (std::to_integer (cursor[2])) << (shift++ * 6u); + case 1: accum |= CONTINUATION.value (std::to_integer (cursor[1])) << (shift++ * 6u); } // describes the bits required to be present for a valid minimally