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 ¶
- func Canonical(text string) string
- func DecodeRuneInString(text string) (r rune, size int)
- func FromUTF8(data []byte) string
- func FromUTF16(units []uint16) string
- func IndexOf(text, search string, from int) int
- func IsSpace(r rune) bool
- func LastIndexOf(text, search string, from int) int
- func Length(text string) int
- func Slice(text string, start int, ends ...int) string
- func Splice(text string, start, end int, insert string) string
- func ToFixed(x float64, digits int) string
- func ToPrecision(x float64, precision int) string
- func ToUTF8(text string) []byte
- func ToUTF16(text string) []uint16
- func Trim(s string) string
- func TrimEnd(s string) string
- func TrimStart(s string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Canonical ¶
Canonical preserves UTF-16 units while giving paired surrogates their ordinary UTF-8 spelling.
func DecodeRuneInString ¶
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 ¶
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 IndexOf ¶
IndexOf implements String.indexOf with UTF-16 positions, including searches for a surrogate half inside a pair.
func IsSpace ¶
IsSpace reports whether r is JavaScript whitespace or a line terminator (the characters String.prototype.trim removes).
func LastIndexOf ¶
LastIndexOf implements String.lastIndexOf, whose from argument bounds the start of the match and clamps negative positions to zero.
func Slice ¶
Slice applies String.slice's unit offsets, including negative offsets, an omitted end and retained surrogate halves.
func Splice ¶
Splice joins the prefix before start, insert, and the suffix beginning at end, using String.slice's UTF-16 offset rules.
func ToFixed ¶
ToFixed is Number.prototype.toFixed for 0 <= digits <= 100: the exact decimal value of x is rounded to digits places, and a tie takes the larger n, as the specification requires (Go's %.1f rounds ties to even). A magnitude of at least 1e21 formats as Number::toString, as step 7 of the specification requires.
func ToPrecision ¶
ToPrecision is Number.prototype.toPrecision for finite positive x and 1 <= precision <= 100.
func ToUTF8 ¶
ToUTF8 replaces lone UTF-16 surrogates, matching a JavaScript string's UTF-8 encoding for operating-system byte APIs.
Types ¶
This section is empty.