praveenbingo commented on a change in pull request #7641:
URL: https://github.com/apache/arrow/pull/7641#discussion_r451391005



##########
File path: cpp/src/gandiva/precompiled/string_ops.cc
##########
@@ -284,10 +285,74 @@ const char* reverse_utf8(gdv_int64 context, const char* 
data, gdv_int32 data_len
   return ret;
 }
 
-// Trim a utf8 sequence
+// Trims whitespaces from the left end of the input utf8 sequence
 FORCE_INLINE
-const char* trim_utf8(gdv_int64 context, const char* data, gdv_int32 data_len,
-                      int32_t* out_len) {
+const char* ltrim_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;
+  // start denotes the first position of non-space characters in the input 
string
+  while (start < data_len && data[start] == ' ') {
+    ++start;
+  }
+
+  // string with no leading spaces, return original string
+  if (start == 0) {
+    *out_len = data_len;
+    return data;
+  }
+
+  // string with all spaces
+  if (start == data_len) {
+    *out_len = 0;
+    return "";
+  }
+
+  // string has some leading spaces and some non-space characters
+  *out_len = data_len - start;
+  return data + start;
+}
+
+// Trims whitespaces from the right end of the input utf8 sequence
+FORCE_INLINE
+const char* rtrim_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 end = data_len - 1;
+  // end denotes the last position of non-space characters in the input string
+  while (end >= 0 && data[end] == ' ') {

Review comment:
       is this the only utf8 space character?




----------------------------------------------------------------
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


Reply via email to