zhjwpku commented on code in PR #156:
URL: https://github.com/apache/iceberg-cpp/pull/156#discussion_r2257646368


##########
src/iceberg/transform_function.cc:
##########
@@ -150,17 +150,25 @@ Result<std::optional<Literal>> 
TruncateTransform::Transform(const Literal& liter
       return NotImplemented("Truncate for Decimal is not implemented yet");
     }
     case TypeId::kString: {
+      // Strings are truncated to a valid UTF-8 string with no more than L 
code points.
       auto value = std::get<std::string>(literal.value());
-      if (value.size() > static_cast<size_t>(width_)) {
-        size_t safe_point = width_;
-        while (safe_point > 0 && (value[safe_point] & 0xC0) == 0x80) {
-          // Find the last valid UTF-8 character boundary before or at width_
-          safe_point--;
+      size_t code_point_count = 0;
+      size_t safe_point = 0;
+
+      for (size_t i = 0; i < value.size(); ++i) {
+        // Start of a new UTF-8 code point
+        if ((value[i] & 0xC0) != 0x80) {

Review Comment:
   done.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to