jsstring

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package jsstring preserves JavaScript UTF-16 units at Go string boundaries. Lone surrogate units use WTF-8; ordinary Unicode strings retain their normal UTF-8 encoding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Canonical

func Canonical(text string) string

Canonical preserves UTF-16 units while giving paired surrogates their ordinary UTF-8 spelling.

func DecodeRuneInString

func DecodeRuneInString(text string) (r rune, size int)

DecodeRuneInString reads a JavaScript code point from UTF-8/WTF-8. Adjacent encoded surrogate halves combine just as UTF-16 codePointAt does after strings are concatenated.

func FromUTF8

func FromUTF8(data []byte) string

FromUTF8 decodes operating-system bytes like Buffer.toString("utf8") and napi_create_string_utf8: each maximal ill-formed subpart becomes one replacement character, and a leading BOM is retained.

func FromUTF16

func FromUTF16(units []uint16) string

FromUTF16 converts UTF-16 without replacing unpaired surrogates.

func IndexOf

func IndexOf(text, search string, from int) int

IndexOf implements String.indexOf with UTF-16 positions, including searches for a surrogate half inside a pair.

func LastIndexOf

func LastIndexOf(text, search string, from int) int

LastIndexOf implements String.lastIndexOf, whose from argument bounds the start of the match and clamps negative positions to zero.

func Length

func Length(text string) int

Length counts JavaScript UTF-16 units in a UTF-8/WTF-8 string.

func Slice

func Slice(text string, start int, ends ...int) string

Slice applies String.slice's unit offsets, including negative offsets, an omitted end and retained surrogate halves.

func Splice

func Splice(text string, start, end int, insert string) string

Splice joins the prefix before start, insert, and the suffix beginning at end, using String.slice's UTF-16 offset rules.

func ToUTF8

func ToUTF8(text string) []byte

ToUTF8 replaces lone UTF-16 surrogates, matching a JavaScript string's UTF-8 encoding for operating-system byte APIs.

func ToUTF16

func ToUTF16(text string) []uint16

ToUTF16 converts UTF-8/WTF-8 to the original JavaScript code units.

Types

This section is empty.

Jump to

Keyboard shortcuts

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