bytesconv

package
v0.0.0-...-391ac19 Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package bytesconv facilitates the interpretation of raw bytes as strings.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidUTF16 is returned when the provided bytes are not valid
	// UTF-16.
	ErrInvalidUTF16 = errors.New("the UTF-16 data is invalid")

	// ErrUnevenUTF16 is returned when the provided bytes are not an even
	// length. The UTF-16 encoding requires an even number of bytes.
	ErrUnevenUTF16 = errors.New("the UTF-16 data is not an even length")
)

Functions

func DecodeString

func DecodeString(p []byte) string

DecodeString attempts to interpret the given bytes as a string. If the bytes are valid UTF-8, they are returned as a string without modification.

If the bytes are not valid UTF-8, it attempts to interpret them as UTF-16. If successful, it converts the bytes to UTF-8 and returns the resulting string.

If a unicode encoding is not detected, or conversion to a string is not successful, it returns the bytes as a Base64 raw URL-encoded string.

func DecodeUTF16

func DecodeUTF16(p []byte, order binary.ByteOrder) string

DecodeUTF16 interprets the given bytes as UTF-16 with the specified byte order and returns the value as a string.

Any invalid characters will be replaced with the unicode replacement character.

func HasUTF16BOM

func HasUTF16BOM(p []byte, order binary.ByteOrder) bool

HasUTF16BOM returns true if the given bytes have a unicode byte order mark with the specified byte order.

func ParseUTF16

func ParseUTF16(p []byte, order binary.ByteOrder) (string, error)

ParseUTF16 parses the given bytes as UTF-16 with the specified byte order and returns the value as a string. If it fails, it returns an error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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