MCPcopy Create free account
hub / github.com/apache/arrow / utf8_length_ignore_invalid

Function utf8_length_ignore_invalid

cpp/src/gandiva/precompiled/string_ops.cc:198–216  ·  view source on GitHub ↗

Count the number of utf8 characters, ignoring invalid char, considering size 1

Source from the content-addressed store, hash-verified

196
197// Count the number of utf8 characters, ignoring invalid char, considering size 1
198FORCE_INLINE
199gdv_int32 utf8_length_ignore_invalid(const char* data, gdv_int32 data_len) {
200 int char_len = 0;
201 int count = 0;
202 for (int i = 0; i < data_len; i += char_len) {
203 char_len = utf8_char_length(data[i]);
204 if (char_len == 0 || i + char_len > data_len) { // invalid byte or incomplete glyph
205 // if invalid byte or incomplete glyph, ignore it
206 char_len = 1;
207 }
208 for (int j = 1; j < char_len; ++j) {
209 if ((data[i + j] & 0xC0) != 0x80) { // bytes following head-byte of glyph
210 char_len += 1;
211 }
212 }
213 ++count;
214 }
215 return count;
216}
217
218// Get the byte position corresponding to a character position for a non-empty utf8
219// sequence

Callers 3

lpad_utf8_int32_utf8Function · 0.85
rpad_utf8_int32_utf8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected