All 161 task packages, including the 21 batch 6 C++17 tasks that passed
gates 1/2, are now in Git. rollout.catalog builds docs/task-catalog.{json,md}
from the task packages, a fresh trace5 calibration (128/128 PASS), every
verified controller receipt on the current task digest, documented holds
and digest-bound difficulty reviews. 123 tasks are usable (6 HARD),
5 are on hold and 33 still need a subprocess-only grader.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
2.1 KiB
C++
86 lines
2.1 KiB
C++
#include "unit_specifiers.h"
|
|
|
|
namespace unit_specifiers {
|
|
namespace detail {
|
|
// A completed scalar leaves both counters zero. Bounds constrain only the
|
|
// immediately following continuation; later continuation bytes use 80..bf.
|
|
bool take_utf8(unsigned char byte, unsigned& remaining, unsigned& received,
|
|
unsigned& lower, unsigned& upper) {
|
|
if (remaining != 0) {
|
|
if (byte < lower || byte > upper) return false;
|
|
--remaining;
|
|
++received;
|
|
lower = 0x80;
|
|
upper = 0xbf;
|
|
if (remaining == 0) received = 0;
|
|
return true;
|
|
}
|
|
if (byte <= 0x7f) {
|
|
received = 0;
|
|
return true;
|
|
}
|
|
if (byte >= 0xc2 && byte <= 0xdf) {
|
|
remaining = 1;
|
|
received = 1;
|
|
lower = 0x80;
|
|
upper = 0xbf;
|
|
return true;
|
|
}
|
|
if (byte == 0xe0) {
|
|
remaining = 2;
|
|
received = 1;
|
|
lower = 0xa0;
|
|
upper = 0xbf;
|
|
return true;
|
|
}
|
|
if ((byte >= 0xe1 && byte <= 0xec) || (byte >= 0xee && byte <= 0xef)) {
|
|
remaining = 2;
|
|
received = 1;
|
|
lower = 0x80;
|
|
upper = 0xbf;
|
|
return true;
|
|
}
|
|
if (byte == 0xed) {
|
|
remaining = 2;
|
|
received = 1;
|
|
lower = 0x80;
|
|
upper = 0x9f;
|
|
return true;
|
|
}
|
|
if (byte == 0xf0) {
|
|
remaining = 3;
|
|
received = 1;
|
|
lower = 0x90;
|
|
upper = 0xbf;
|
|
return true;
|
|
}
|
|
if (byte >= 0xf1 && byte <= 0xf3) {
|
|
remaining = 3;
|
|
received = 1;
|
|
lower = 0x80;
|
|
upper = 0xbf;
|
|
return true;
|
|
}
|
|
if (byte == 0xf4) {
|
|
remaining = 3;
|
|
received = 1;
|
|
lower = 0x80;
|
|
upper = 0x8f;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
} // namespace detail
|
|
|
|
bool valid_utf8(std::string_view bytes) {
|
|
unsigned remaining = 0;
|
|
unsigned received = 0;
|
|
unsigned lower = 0x80;
|
|
unsigned upper = 0xbf;
|
|
for (unsigned char byte : bytes) {
|
|
if (!detail::take_utf8(byte, remaining, received, lower, upper)) return false;
|
|
}
|
|
return remaining == 0;
|
|
}
|
|
} // namespace unit_specifiers
|