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

Function lpad_utf8_int32_utf8

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

Source from the content-addressed store, hash-verified

2043}
2044
2045FORCE_INLINE
2046const char* lpad_utf8_int32_utf8(gdv_int64 context, const char* text, gdv_int32 text_len,
2047 gdv_int32 return_length, const char* fill_text,
2048 gdv_int32 fill_text_len, gdv_int32* out_len) {
2049 // if the text length or the defined return length (number of characters to return)
2050 // is <=0, then return an empty string.
2051 return_length = std::min(max_str_length, return_length);
2052 return_length = std::max(min_str_length, return_length);
2053 if (text_len == 0 || return_length <= 0) {
2054 *out_len = 0;
2055 return "";
2056 }
2057
2058 // count the number of utf8 characters on text, ignoring invalid bytes
2059 int actual_text_len = utf8_length_ignore_invalid(text, text_len);
2060
2061 if (return_length == actual_text_len ||
2062 (return_length > actual_text_len && fill_text_len == 0)) {
2063 // case where the return length is same as the text's length, or if it need to
2064 // fill into text but "fill_text" is empty, then return text directly.
2065 *out_len = text_len;
2066 return text;
2067 }
2068 if (return_length < actual_text_len) {
2069 // case where it truncates the result on return length.
2070 *out_len = utf8_byte_pos(context, text, text_len, return_length);
2071 return text;
2072 }
2073
2074 gdv_int32 chars_to_pad = return_length - actual_text_len;
2075
2076 // FAST PATH: Single-byte fill (most common - space padding)
2077 if (fill_text_len == 1) {
2078 gdv_int32 out_len_bytes = chars_to_pad + text_len;
2079 gdv_binary ret =
2080 reinterpret_cast<gdv_binary>(gdv_fn_context_arena_malloc(context, out_len_bytes));
2081 if (ret == nullptr) {
2082 gdv_fn_context_set_error_msg(context,
2083 "Could not allocate memory for output string");
2084 *out_len = 0;
2085 return "";
2086 }
2087 memset(ret, fill_text[0], chars_to_pad);
2088 memcpy(ret + chars_to_pad, text, text_len);
2089 *out_len = out_len_bytes;
2090 return ret;
2091 }
2092
2093 // GENERAL PATH: Multi-byte fill - use evaluate_return_char_length for buffer size
2094 gdv_int32 return_char_length = evaluate_return_char_length(
2095 text_len, actual_text_len, return_length, fill_text, fill_text_len);
2096 gdv_binary ret = reinterpret_cast<gdv_binary>(
2097 gdv_fn_context_arena_malloc(context, return_char_length));
2098 if (ret == nullptr) {
2099 gdv_fn_context_set_error_msg(context, "Could not allocate memory for output string");
2100 *out_len = 0;
2101 return "";
2102 }

Callers 2

lpad_utf8_int32Function · 0.85
TESTFunction · 0.85

Calls 6

utf8_byte_posFunction · 0.85
fill_buffer_with_patternFunction · 0.85

Tested by 1

TESTFunction · 0.68