liyafan82 commented on a change in pull request #7402: URL: https://github.com/apache/arrow/pull/7402#discussion_r438611543
########## File path: cpp/src/gandiva/precompiled/string_ops.cc ########## @@ -284,6 +284,42 @@ const char* reverse_utf8(gdv_int64 context, const char* data, gdv_int32 data_len return ret; } +// Trim a utf8 sequence +FORCE_INLINE +const char* trim_utf8(gdv_int64 context, const char* data, gdv_int32 data_len, + int32_t* out_len) { + if (data_len == 0) { + *out_len = 0; + return ""; + } + + gdv_int32 start = 0, end = data_len - 1; + // start and end denote the first and last positions of non-space characters in string respectively + while (start <= end && data[start] == ' ') { + ++start; + } + while (end >= start && data[end] == ' ') { + --end; + } + + // string with all spaces + if (start > end) { + *out_len = 0; + return ""; + } + Review comment: Do we need a quick path that return the original string if there are no leading/trailing spaces? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org