You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wincmd/ntfs/utf16/decode.go

19 lines
496 B
Go

package utf16
import (
"encoding/binary"
"unicode/utf16"
)
// Decode the input data as UTF-16 using the provided byte order and convert the result to a string. The input data
// length must be a multiple of 2. DecodeString will panic if that is not the case.
func DecodeString(b []byte, bo binary.ByteOrder) string {
slen := len(b) / 2
shorts := make([]uint16, slen)
for i := 0; i < slen; i++ {
bi := i * 2
shorts[i] = bo.Uint16(b[bi : bi+2])
}
return string(utf16.Decode(shorts))
}