MCPcopy Create free account
hub / github.com/cli/cli / truncateAsUTF16

Function truncateAsUTF16

pkg/cmd/run/view/logs.go:336–344  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

3344 a😅�
335*/
336func 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
346func matchFileInZIPArchive(zr *zip.Reader, re *regexp.Regexp) *zip.File {
347 for _, file := range zr.File {

Callers 1

getJobNameForLogFilenameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…