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

Function right_utf8_int32

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

Returns the x rightmost characters of a given string. Cases: RIGHT("TestString", 10) => "TestString" RIGHT("TestString", 3) => "ing" RIGHT("TestString", -3) => "tString"

Source from the content-addressed store, hash-verified

2236// RIGHT("TestString", 3) => "ing"
2237// RIGHT("TestString", -3) => "tString"
2238FORCE_INLINE
2239const char* right_utf8_int32(gdv_int64 context, const char* text, gdv_int32 text_len,
2240 gdv_int32 number, gdv_int32* out_len) {
2241 // returns the 'number' left most characters of a given text
2242 if (text_len == 0 || number == 0) {
2243 *out_len = 0;
2244 return "";
2245 }
2246
2247 // initially counts the number of utf8 characters in the defined text
2248 int32_t char_count = utf8_length(context, text, text_len);
2249
2250 // char_count is zero if input has invalid utf8 char
2251 if (char_count == 0) {
2252 *out_len = 0;
2253 return "";
2254 }
2255
2256 // case where right('abcdef', -6) -> "" and right('abcdef', -7) -> ""
2257 if (number < 0 && -(number) >= char_count) {
2258 *out_len = 0;
2259 return "";
2260 }
2261
2262 int32_t start_char_pos; // the char result start position (inclusive)
2263
2264 if (number > 0) {
2265 // case where right('abc', 5) ==> 'abc' start_char_pos=1.
2266 start_char_pos = (char_count > number) ? char_count - number : 0;
2267 } else {
2268 start_char_pos = number * -1;
2269 }
2270
2271 // calculate the start byte position
2272 int32_t start_byte_pos = utf8_byte_pos(context, text, text_len, start_char_pos);
2273
2274 // calculate output length
2275 *out_len = (text_len - start_byte_pos);
2276 return text + start_byte_pos;
2277}
2278
2279FORCE_INLINE
2280const char* binary_string(gdv_int64 context, const char* text, gdv_int32 text_len,

Callers 1

TESTFunction · 0.85

Calls 2

utf8_lengthFunction · 0.85
utf8_byte_posFunction · 0.85

Tested by 1

TESTFunction · 0.68