38 return (
static_cast<unsigned char>(
byte) & 0xC0U) == 0x80U;
49 const auto byte =
static_cast<unsigned char>(lead);
65 return static_cast<unsigned char>(lead) >= 0xF0U ? 2 : 1;
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)) {
std::optional< std::string > text
The text, where the value is a string literal or a name bound to one.
Definition discover.cc:612
bool IsContinuation(char byte)
Whether byte is a continuation byte – the middle of a character.
Definition utf8.h:37
size_t SequenceWidth(char lead)
Bytes in the sequence lead starts, from the lead byte alone.
Definition utf8.h:48
size_t Utf16Units(char lead)
UTF-16 code units the character at lead occupies: 2 above the BMP, else.
Definition utf8.h:64
bool IsValid(std::string_view text)
Whether text is well-formed UTF-8.
Definition utf8.h:77