Documentation
¶
Overview ¶
Package text ports upstream packages/coding-agent/src/utils/text.ts: the leading byte order mark helpers every Pi reader applies before parsing user-authored JSON, markdown, and text files.
Index ¶
- func QuoteUTF16(units []uint16) []byte
- func SanitizeBinaryOutput(s string) string
- func SplitBom(content string) (mark, text string)
- func StripANSI(b []byte) []byte
- func StripANSIString(s string) string
- func StripBom(content string) string
- func StripBomBytes(content []byte) []byte
- func UTF16Units(value string) []uint16
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func QuoteUTF16 ¶
Ports packages/coding-agent/src/modes/rpc/jsonl.ts (JSON.stringify string encoding). QuoteUTF16 returns a JSON.stringify-compatible string token, preserving lone UTF-16 units as escapes instead of replacing them with U+FFFD. It does not apply HTML escaping.
func SanitizeBinaryOutput ¶
SanitizeBinaryOutput mirrors upstream shell.ts sanitizeBinaryOutput: drop control characters other than tab, newline and carriage return, and the Unicode format characters U+FFF9..U+FFFB (they crash string-width). Invalid UTF-8 bytes become U+FFFD, as upstream's decoder would have produced before sanitizing. Text with nothing to change is returned as it is, without a copy.
func SplitBom ¶
SplitBom splits a leading UTF-8 byte order mark from decoded text. It returns the mark ("" when absent) and the remaining text. Mirrors upstream splitBom.
func StripANSI ¶
StripANSI mirrors upstream utils/ansi.ts stripAnsi: it removes every ansiRegex match. Text without an introducer is returned as it is.
func StripANSIString ¶
StripANSIString is StripANSI of a string. Text without an introducer is returned as it is, without a copy.
func StripBom ¶
StripBom removes a leading UTF-8 byte order mark from decoded text. Mirrors upstream stripBom.
func StripBomBytes ¶
StripBomBytes is StripBom for file contents read as bytes, so JSON readers can strip the mark before decoding without a string round trip.
func UTF16Units ¶
UTF16Units converts Go strings to JavaScript string units. WTF-8 carries lone surrogates without collapsing them into replacement characters; other malformed UTF-8 follows Go's replacement-character decoding.
Types ¶
This section is empty.