fallintoplace commented on code in PR #1198:
URL: https://github.com/apache/iceberg-go/pull/1198#discussion_r3439084374


##########
transforms.go:
##########
@@ -477,6 +484,18 @@ func (t TruncateTransform) Transformer(src Type) 
(func(any) any, error) {
                ErrInvalidArgument, src)
 }
 
+func truncateString(s string, width int) string {
+       for idx := range s {
+               if width == 0 {
+                       return s[:idx]

Review Comment:
   Yeah, I can see why it looks similar at first glance.
   
   The difference is that the old code was cutting strings by byte count. So 
for something like `"éx"` with width `1`, it could return only the first byte 
of `"é"`, which makes the result invalid UTF-8.
   
   This version still slices the original string, but it only slices at indexes 
from `range s`, which are valid UTF-8 character boundaries. So width `1` 
returns `"é"` instead of half of that character.
   
   Binary is still byte-based, so I split that into a separate branch.
   



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