Helper function to decode a byte slice (UTF-16LE) to UTF-8
(data []byte)
| 72 | |
| 73 | // Helper function to decode a byte slice (UTF-16LE) to UTF-8 |
| 74 | func 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 | } |
no outgoing calls
no test coverage detected