txtutil

package
v4.46.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeQuoted

func EncodeQuoted(t string) string

EncodeQuoted encodes a string into a series of quoted 255-octet chunks. That is, when decoded each chunk would be 255-octets with the remainder in the last chunk.

The output looks like:

`""`                                      empty
`"255\"octets"`                           quotes are escaped
`"255\\octets"`                           backslashes are escaped
`"255octets" "255octets" "remainder"`     long strings are chunked

func EncodeSingle added in v4.38.0

func EncodeSingle(t string) string

EncodeSingle encodes a string as a single quoted value without splitting into 255-octet chunks. This is intended for user-facing display (e.g., diff preview) where the chunked representation is confusing.

func ParseQuoted

func ParseQuoted(s string) (string, error)

ParseQuoted parses a string of RFC1035-style quoted items. The resulting items are then joined into one string. This is useful for parsing TXT records. Examples: `foo` => foo `"foo"` => foo `"f\"oo"` => f"oo `"f\\oo"` => f\oo `"foo" "bar"` => foobar `"foo" bar` => foobar.

func ToChunks

func ToChunks(s string) []string

ToChunks returns the string as chunks of 255-octet strings (the last string being the remainder).

Types

type State

type State int

State denotes the parser state.

const (
	// StateStart indicates parser is looking for a non-space.
	StateStart State = iota

	// StateUnquoted indicates parser is in a run of unquoted text.
	StateUnquoted

	// StateQuoted indicates parser is in quoted text.
	StateQuoted

	// StateBackslash indicates the last char was backlash in a quoted string.
	StateBackslash

	// StateWantSpace indicates parser expects a space (the previous token was a closing quote).
	StateWantSpace
)

func (State) String

func (i State) String() string

Jump to

Keyboard shortcuts

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