MCPcopy Create free account
hub / github.com/aboSamoor/pycld2 / ScriptScanner

Class ScriptScanner

cld2/internal/getonescriptspan.h:49–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47
48
49class ScriptScanner {
50 public:
51 ScriptScanner(const char* buffer, int buffer_length, bool is_plain_text);
52 ScriptScanner(const char* buffer, int buffer_length, bool is_plain_text,
53 bool any_text, bool any_script);
54 ~ScriptScanner();
55
56 // Copy next run of same-script non-tag letters to buffer [NUL terminated]
57 bool GetOneScriptSpan(LangSpan* span);
58
59 // Force Latin and Cyrillic scripts to be lowercase
60 void LowerScriptSpan(LangSpan* span);
61
62 // Copy next run of same-script non-tag letters to buffer [NUL terminated]
63 // Force Latin and Cyrillic scripts to be lowercase
64 bool GetOneScriptSpanLower(LangSpan* span);
65
66 // Copy next run of non-tag characters to buffer [NUL terminated]
67 // This just removes tags and removes entities
68 // Buffer has leading space
69 bool GetOneTextSpan(LangSpan* span);
70
71 // Maps byte offset in most recent GetOneScriptSpan/Lower
72 // span->text [0..text_bytes] into an additional byte offset from
73 // span->offset, to get back to corresponding text in the original
74 // input buffer.
75 // text_offset must be the first byte
76 // of a UTF-8 character, or just beyond the last character. Normally this
77 // routine is called with the first byte of an interesting range and
78 // again with the first byte of the following range.
79 int MapBack(int text_offset);
80
81 const char* GetBufferStart() {return start_byte_;};
82
83 private:
84 // Skip over tags and non-letters
85 int SkipToFrontOfSpan(const char* src, int len, int* script);
86
87 const char* start_byte_; // Starting byte of buffer to scan
88 const char* next_byte_; // First unscanned byte
89 const char* next_byte_limit_; // Last byte + 1
90 int byte_length_; // Bytes left: next_byte_limit_ - next_byte_
91
92 bool is_plain_text_; // true fo text, false for HTML
93 char* script_buffer_; // Holds text with expanded entities
94 char* script_buffer_lower_; // Holds lowercased text
95 bool letters_marks_only_; // To distinguish scriptspan of one
96 // letters/marks vs. any mixture of text
97 bool one_script_only_; // To distinguish scriptspan of one
98 // script vs. any mixture of scripts
99 int exit_state_; // For tag parser kTagParseTbl_0, based
100 // on letters_marks_only_
101 public :
102 // Expose for debugging
103 OffsetMap map2original_; // map from script_buffer_ to buffer
104 OffsetMap map2uplow_; // map from script_buffer_lower_ to script_buffer_
105};
106

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected