Documentation
¶
Index ¶
- func DeleteAllValues(container *Node)
- func DeleteValue(container *Node, key string)
- func EscapeString(s string) string
- func ExtractBool(kv *Node) (bool, bool)
- func ExtractFloat64(kv *Node) (float64, bool)
- func ExtractInt(kv *Node) (int, bool)
- func ExtractInt64(kv *Node) (int64, bool)
- func ExtractIntSlice(kv *Node) ([]int, bool)
- func ExtractRaw(kv *Node) (any, bool)
- func ExtractString(kv *Node) (string, bool)
- func ExtractStringMap(container *Node) map[string]string
- func ExtractStringSlice(kv *Node) ([]string, bool)
- func ExtractUint64(kv *Node) (uint64, bool)
- func HasValue(container *Node, key string) bool
- func KeyValueName(kv *Node) string
- func SetAny(container *Node, key string, value any) error
- func SetMultilineString(container *Node, key, value string) error
- func SetValue(container *Node, key string, encoded []byte, kind NodeKind) error
- func StripQuotes(s string) string
- func TableHeaderKey(table *Node) string
- func UnescapeString(s string) string
- type Node
- func AppendArrayTableEntryAfter(root *Node, key string) *Node
- func EnsureChildSubTable(root *Node, parent *Node, prefix, key string) *Node
- func EnsureChildTable(root *Node, parent *Node, key string) *Node
- func FindArrayTableNodes(root *Node, key string) []*Node
- func KeyValueValue(kv *Node) *Node
- func Parse(input []byte) (*Node, error)
- func ParseReader(r io.Reader) (*Node, error)
- type NodeKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteAllValues ¶
func DeleteAllValues(container *Node)
DeleteAllValues removes all key-value children from a container, preserving table/array-table headers and other non-KV nodes.
func DeleteValue ¶
DeleteValue removes a key-value from the container.
func EscapeString ¶
EscapeString escapes special characters for a TOML basic string.
func ExtractBool ¶
ExtractBool extracts a bool value from a NodeKeyValue.
func ExtractFloat64 ¶
ExtractFloat64 extracts a float64 value from a NodeKeyValue.
func ExtractInt ¶
ExtractInt extracts an int value from a NodeKeyValue.
func ExtractInt64 ¶
ExtractInt64 extracts an int64 value from a NodeKeyValue.
func ExtractIntSlice ¶
ExtractIntSlice extracts a []int from a NodeKeyValue whose value is a NodeArray.
func ExtractRaw ¶
ExtractRaw extracts the value from a NodeKeyValue as a natural Go type (string, int64, float64, bool, or []any). Used for custom unmarshalers.
func ExtractString ¶
ExtractString extracts a string value from a NodeKeyValue.
func ExtractStringMap ¶
ExtractStringMap reads all key-value pairs from a container node (typically a NodeTable) as map[string]string.
func ExtractStringSlice ¶
ExtractStringSlice extracts a []string from a NodeKeyValue whose value is a NodeArray.
func ExtractUint64 ¶
ExtractUint64 extracts a uint64 value from a NodeKeyValue.
func KeyValueName ¶
KeyValueName returns the key name from a NodeKeyValue node. For simple keys like `name = "value"`, returns "name". For dotted keys like `a.b.c = "value"`, returns "a.b.c".
func SetMultilineString ¶
SetMultilineString sets a string value using TOML multiline basic string syntax.
func StripQuotes ¶
StripQuotes removes TOML quotes from a raw string value. Handles basic (""), literal (”), multiline ("""/”'), and bare strings.
func TableHeaderKey ¶
TableHeaderKey returns the dotted key from a NodeTable or NodeArrayTable header. For `[a.b.c]`, returns "a.b.c".
func UnescapeString ¶
UnescapeString processes TOML escape sequences in a basic string.
Types ¶
type Node ¶
func AppendArrayTableEntryAfter ¶
AppendArrayTableEntryAfter appends a new [[key]] array-table entry, inserting it after the last existing [[key]] or at the end.
func EnsureChildSubTable ¶
EnsureChildSubTable finds or creates a [prefix.key] sub-table scoped to parent.
func EnsureChildTable ¶
EnsureChildTable finds or creates a [key] table as a child of parent. Unlike the document API's EnsureTable which always appends at root end, this inserts the new table immediately after parent in root.Children, fixing scoping for tables inside array-table entries.
func FindArrayTableNodes ¶
FindArrayTableNodes returns all [[key]] array-table nodes from root children.
func KeyValueValue ¶
KeyValueValue returns the value node from a NodeKeyValue node. The value is the first non-whitespace child after the NodeEquals.
func Parse ¶
Parse consumes raw TOML input and returns a CST document node. Every token becomes a leaf node; structural nodes group their children. Concatenating all leaf Raw bytes reproduces the original input byte-for-byte.
func ParseReader ¶
ParseReader consumes TOML from an io.Reader and returns a CST document node.
type NodeKind ¶
type NodeKind int
const ( NodeDocument NodeKind = iota NodeTable // [table] NodeArrayTable // [[array-of-tables]] NodeKeyValue // key = value NodeKey // bare or quoted key NodeDottedKey // a.b.c NodeEquals // = // Values NodeString NodeInteger NodeFloat NodeBool NodeDateTime NodeArray // [1, 2, 3] NodeInlineTable // {a = 1, b = 2} // Trivia NodeComment // # ... NodeWhitespace // spaces, tabs NodeNewline // \n, \r\n // Punctuation NodeBracketOpen // [ NodeBracketClose // ] NodeBraceOpen // { NodeBraceClose // } NodeComma // , NodeDot // . )
func EncodeMultilineString ¶
EncodeMultilineString encodes a string as TOML multiline basic string.