wtf16

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Windows UTF-16 strings can contain unpaired surrogates, which can't be decoded into a valid UTF-8 string. This file defines a set of functions that can be used to encode and decode potentially ill-formed UTF-16 strings by using the [the WTF-8 encoding](https://simonsapin.github.io/wtf-8/).

WTF-8 is a strict superset of UTF-8, i.e. any string that is well-formed in UTF-8 is also well-formed in WTF-8 and the content is unchanged. Also, the conversion never fails and is lossless.

The benefit of using WTF-8 instead of UTF-8 when decoding a UTF-16 string is that the conversion is lossless even for ill-formed UTF-16 strings. This property allows to read an ill-formed UTF-16 string, convert it to a Go string, and convert it back to the same original UTF-16 string.

See go.dev/issues/59971 for more info.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(dst []uint16, s string) []uint16

Encode returns the potentially ill-formed UTF-16 encoding of s.

func WTF8Decode

func WTF8Decode(dst []byte, src ...uint16) ([]byte, int)

WTF8Decode returns the WTF-8 encoding of the potentially ill-formed UTF-16 src.

func WTF8DecodeAll

func WTF8DecodeAll(dst []byte, src ...uint16) []byte

func WTF8DecodedSize

func WTF8DecodedSize(s ...uint16) (n int, canDecodeInPlace bool)

Types

type String

type String string

func AsString

func AsString(s []uint16) String

func (String) Slice

func (s String) Slice() []uint16

Jump to

Keyboard shortcuts

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