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

Function ltrim_utf8_utf8

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

Trims characters present in the trim text from the left end of the base text

Source from the content-addressed store, hash-verified

385
386// Trims characters present in the trim text from the left end of the base text
387FORCE_INLINE
388const char* ltrim_utf8_utf8(gdv_int64 context, const char* basetext,
389 gdv_int32 basetext_len, const char* trimtext,
390 gdv_int32 trimtext_len, int32_t* out_len) {
391 if (basetext_len == 0) {
392 *out_len = 0;
393 return "";
394 } else if (trimtext_len == 0) {
395 *out_len = basetext_len;
396 return basetext;
397 }
398
399 gdv_int32 start_ptr, char_len;
400 // scan the base text from left to right and increment the start pointer till
401 // there is a character which is not present in the trim text
402 for (start_ptr = 0; start_ptr < basetext_len; start_ptr += char_len) {
403 char_len = utf8_char_length(basetext[start_ptr]);
404 if (char_len == 0 || start_ptr + char_len > basetext_len) {
405 // invalid byte or incomplete glyph
406 set_error_for_invalid_utf(context, basetext[start_ptr]);
407 *out_len = 0;
408 return "";
409 }
410 if (!is_substr_utf8_utf8(trimtext, trimtext_len, basetext + start_ptr, char_len)) {
411 break;
412 }
413 }
414
415 *out_len = basetext_len - start_ptr;
416 return basetext + start_ptr;
417}
418
419// Trims characters present in the trim text from the right end of the base text
420FORCE_INLINE

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68