27#include "UTF8Util.hpp"
39inline uint32_t DecodeCodePoint23(
const char* str,
size_t charLength) {
40 const unsigned char lead =
static_cast<unsigned char>(str[0]);
41 if (charLength == 2) {
42 return ((lead & 0x1FU) << 6) |
43 (
static_cast<unsigned char>(str[1]) & 0x3FU);
45 return ((lead & 0x0FU) << 12) |
46 ((
static_cast<unsigned char>(str[1]) & 0x3FU) << 6) |
47 (
static_cast<unsigned char>(str[2]) & 0x3FU);
81 void EnableCharLevel() {
bmpCandidates.assign(0x10000 / 64, 0); }
90 void MarkCharCandidate(uint32_t codePoint) {
91 if (CharLevel() && codePoint < 0x10000) {
92 bmpCandidates[codePoint >> 6] |= uint64_t(1) << (codePoint & 63);
96 bool IsCharCandidate(uint32_t codePoint)
const {
98 return (
bmpCandidates[codePoint >> 6] >> (codePoint & 63)) & 1;
101 void MarkAllCandidates() {
102 for (
size_t b = 0; b < 256; b++) {
118 UTF8Util::kLastIdeographicDescriptionOperator <= 0xFFFF,
119 "IDS operator range must lie in the 3-byte UTF-8 block");
121 cp <= UTF8Util::kLastIdeographicDescriptionOperator; cp++) {
122 if (UTF8Util::IdeographicDescriptionOperatorArity(cp) == 0) {
127 MarkCharCandidate(cp);
130 for (
size_t b = 0; b < 0x80; b++) {
150inline size_t AsciiRunLength(
const char* str,
size_t len) {
152 for (; pos +
sizeof(uint64_t) <= len; pos +=
sizeof(uint64_t)) {
154 std::memcpy(&word, str + pos,
sizeof(word));
155 if ((word & UINT64_C(0x8080808080808080)) != 0) {
161 for (; pos < len; pos++) {
162 if (
static_cast<unsigned char>(str[pos]) >= 0x80) {
176inline size_t SkipNonCandidateBytes(
const Utf8SkipTable& table,
const char* str,
180 const unsigned char lead =
static_cast<unsigned char>(str[pos]);
182 if (!table.asciiHasCandidates) {
183 pos += AsciiRunLength(str + pos, len - pos);
186 if (table.candidate[lead]) {
193 if (charLength == 0 || charLength > len - pos) {
196 if (table.CharLevel() && (charLength == 2 || charLength == 3)) {
202 if (table.IsCharCandidate(DecodeCodePoint23(str + pos, charLength))) {
205 }
else if (table.candidate[lead]) {
static size_t NextCharLengthNoException(const char *str)
Returns the length in byte for the next UTF8 character.
Definition UTF8Util.hpp:50
static const uint32_t kFirstIdeographicDescriptionOperator
Code point bounds of the ideographic description operators recognized by IdeographicDescriptionOperat...
Definition UTF8Util.hpp:121
Per-byte lookup table describing which byte values may begin a dictionary key.
Definition Utf8SkipScan.hpp:56
bool candidate[256]
candidate[b] is true when byte value b may begin a dictionary key (or is the lead byte of an ideograp...
Definition Utf8SkipScan.hpp:62
std::vector< uint64_t > bmpCandidates
Optional character-level refinement: one bit per BMP code point (U+0000..U+FFFF, 8 KiB).
Definition Utf8SkipScan.hpp:77
bool asciiHasCandidates
True when any ASCII byte value is a candidate; disables the bulk ASCII-run scan.
Definition Utf8SkipScan.hpp:67
void DisableCharLevel()
Permanently falls back to lead-byte filtering, e.g.
Definition Utf8SkipScan.hpp:88
void Finalize()
Must be called after candidate[] is filled and before the table is used.
Definition Utf8SkipScan.hpp:116