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:2133–2198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2131}
2132
2133FORCE_INLINE
2134const char* lpad_utf8_int32_utf8(gdv_int64 context, const char* text, gdv_int32 text_len,
2135 gdv_int32 return_length, const char* fill_text,
2136 gdv_int32 fill_text_len, gdv_int32* out_len) {
2137 // if the text length or the defined return length (number of characters to return)
2138 // is <=0, then return an empty string.
2139 return_length = std::min(max_str_length, return_length);
2140 return_length = std::max(min_str_length, return_length);
2141 if (text_len == 0 || return_length <= 0) {
2142 *out_len = 0;
2143 return "";
2144 }
2145
2146 // count the number of utf8 characters on text, ignoring invalid bytes
2147 int actual_text_len = utf8_length_ignore_invalid(text, text_len);
2148
2149 if (return_length == actual_text_len ||
2150 (return_length > actual_text_len && fill_text_len == 0)) {
2151 // case where the return length is same as the text's length, or if it need to
2152 // fill into text but "fill_text" is empty, then return text directly.
2153 *out_len = text_len;
2154 return text;
2155 }
2156 if (return_length < actual_text_len) {
2157 // case where it truncates the result on return length.
2158 *out_len = utf8_byte_pos(context, text, text_len, return_length);
2159 return text;
2160 }
2161
2162 gdv_int32 chars_to_pad = return_length - actual_text_len;
2163
2164 // FAST PATH: Single-byte fill (most common - space padding)
2165 if (fill_text_len == 1) {
2166 gdv_int32 out_len_bytes = chars_to_pad + text_len;
2167 gdv_binary ret =
2168 reinterpret_cast<gdv_binary>(gdv_fn_context_arena_malloc(context, out_len_bytes));
2169 if (ret == nullptr) {
2170 gdv_fn_context_set_error_msg(context,
2171 "Could not allocate memory for output string");
2172 *out_len = 0;
2173 return "";
2174 }
2175 memset(ret, fill_text[0], chars_to_pad);
2176 memcpy(ret + chars_to_pad, text, text_len);
2177 *out_len = out_len_bytes;
2178 return ret;
2179 }
2180
2181 // GENERAL PATH: Multi-byte fill - use evaluate_return_char_length for buffer size
2182 gdv_int32 return_char_length = evaluate_return_char_length(
2183 text_len, actual_text_len, return_length, fill_text, fill_text_len);
2184 gdv_binary ret = reinterpret_cast<gdv_binary>(
2185 gdv_fn_context_arena_malloc(context, return_char_length));
2186 if (ret == nullptr) {
2187 gdv_fn_context_set_error_msg(context, "Could not allocate memory for output string");
2188 *out_len = 0;
2189 return "";
2190 }

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