* If you're reading this comment by necessity, I'm sorry and if you're reading it for fun, you're welcome, you weirdo. What is the length of this string "a😅😅"? If you said 9 you'd be right. If you said 3 or 5 you might also be right! Here's a summary: "a" takes 1 byte (`\x61`) "😅" takes 4 `byte
(str string, max int)
| 334 | 4 a😅� |
| 335 | */ |
| 336 | func truncateAsUTF16(str string, max int) string { |
| 337 | // Encode the string to UTF-16 to count code units |
| 338 | utf16Encoded := utf16.Encode([]rune(str)) |
| 339 | if len(utf16Encoded) > max { |
| 340 | // Decode back to UTF-8 up to the max length |
| 341 | str = string(utf16.Decode(utf16Encoded[:max])) |
| 342 | } |
| 343 | return strings.TrimSpace(str) |
| 344 | } |
| 345 | |
| 346 | func matchFileInZIPArchive(zr *zip.Reader, re *regexp.Regexp) *zip.File { |
| 347 | for _, file := range zr.File { |
no outgoing calls
no test coverage detected
searching dependent graphs…