77inline bool IsValid(std::string_view text) {
80 static constexpr std::uint32_t kSmallest[] = {0, 0, 0x80, 0x800, 0x10000};
82 while (at < text.size()) {
83 const auto lead =
static_cast<unsigned char>(text[at]);
89 std::uint32_t point = 0;
90 if ((lead & 0xE0U) == 0xC0U) {
93 }
else if ((lead & 0xF0U) == 0xE0U) {
96 }
else if ((lead & 0xF8U) == 0xF0U) {
104 if (text.size() - at < width) {
107 for (
size_t index = 1; index < width; ++index) {
111 point = (point << 6U) |
112 (
static_cast<unsigned char>(text[at + index]) & 0x3FU);
114 if (point < kSmallest[width] || point > 0x10FFFFU ||
115 (point >= 0xD800U && point <= 0xDFFFU)) {