MCPcopy
hub / github.com/spicetify/cli / decodeUTF16LE

Function decodeUTF16LE

src/utils/file-utils.go:74–86  ·  view source on GitHub ↗

Helper function to decode a byte slice (UTF-16LE) to UTF-8

(data []byte)

Source from the content-addressed store, hash-verified

72
73// Helper function to decode a byte slice (UTF-16LE) to UTF-8
74func decodeUTF16LE(data []byte) ([]byte, error) {
75 if len(data)%2 != 0 {
76 return nil, fmt.Errorf("invalid UTF-16LE data length")
77 }
78
79 uint16s := make([]uint16, len(data)/2)
80 for i := 0; i < len(data)/2; i++ {
81 uint16s[i] = binary.LittleEndian.Uint16(data[i*2:])
82 }
83
84 runes := utf16.Decode(uint16s)
85 return []byte(string(runes)), nil
86}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected