utf16

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeUTF16LE

func DecodeUTF16LE(b []byte) string

DecodeUTF16LE decodes UTF-16 little endian bytes to a string

This function takes a byte slice and decodes it to a string. It creates a slice of uint16 values with half the length of the byte slice, and fills it with the UTF-16 little endian decoded values. Then, it uses the utf16.Decode function to convert the uint16 slice to a string.

Returns:

  • A string representing the UTF-16 little endian decoded byte slice.

func EncodeUTF16LE

func EncodeUTF16LE(s string) []byte

EncodeUTF16LE encodes a string to UTF-16 little endian bytes

This function takes a string and encodes it to UTF-16 little endian bytes. It uses the utf16.Encode function to convert the string to a slice of uint16 values. Then, it creates a byte slice with twice the length of the utf16le slice, and fills it with the UTF-16 little endian encoded values.

Returns:

  • A byte slice representing the UTF-16 little endian encoded string.

func IsUTF16LE added in v1.0.3

func IsUTF16LE(b []byte) bool

IsUTF16LE checks if a byte slice is valid UTF-16LE encoded data

This function takes a byte slice and checks if it represents valid UTF-16LE encoded data. It verifies that: 1. The length is even (UTF-16 uses 2 bytes per code unit) 2. Each code unit has 0x00 in the high byte, indicating ASCII range characters

Note: This is a simplified check that only validates ASCII range characters. For full UTF-16LE validation, surrogate pairs and non-ASCII characters would need to be handled.

Returns:

  • true if the byte slice appears to be valid UTF-16LE ASCII text
  • false otherwise

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL