edponce commented on a change in pull request #10869:
URL: https://github.com/apache/arrow/pull/10869#discussion_r700497337



##########
File path: cpp/src/arrow/compute/kernels/scalar_string.cc
##########
@@ -527,6 +520,42 @@ struct Utf8CapitalizeTransform : public 
StringTransformBase {
 template <typename Type>
 using Utf8Capitalize = StringTransformExec<Type, Utf8CapitalizeTransform>;
 
+struct Utf8TitleTransform : public FunctionalCaseMappingTransform {
+  int64_t Transform(const uint8_t* input, int64_t input_string_ncodeunits,
+                    uint8_t* output) {
+    uint8_t* output_start = output;
+    const uint8_t* end = input + input_string_ncodeunits;
+    const uint8_t* next = input;
+    bool is_next_upper = true;
+    while ((input = next) < end) {
+      uint32_t codepoint;
+      if (ARROW_PREDICT_FALSE(!util::UTF8Decode(&next, &codepoint))) {
+        return kTransformError;
+      }
+      if (IsCasedCharacterUnicode(codepoint)) {
+        // Lower/uppercase current codepoint and
+        // prepare to lowercase next consecutive cased codepoints
+        output = is_next_upper
+                     ? util::UTF8Encode(output,
+                                        
UTF8UpperTransform::TransformCodepoint(codepoint))
+                     : util::UTF8Encode(
+                           output, 
UTF8LowerTransform::TransformCodepoint(codepoint));
+        is_next_upper = false;
+      } else {
+        // Copy current uncased codepoint and
+        // prepare to uppercase next cased codepoint
+        std::memcpy(output, input, next - input);

Review comment:
       I originally used `std::copy` and ran some benchmarks and it was faster 
to use `std::memcpy` (not negligible). There are quite a few cases where 
`std::memcpy` is used.




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to