Documentation
¶
Overview ¶
Package format implements the string, key, and number rendering rules of the TOON specification.
Index ¶
- func EncodeKey(key string) (string, error)
- func FormatNumber(f float64) string
- func FormatString(s string, ctx Context) (string, error)
- func IsUnquotedKey(key string) bool
- func NeedsQuoting(s string, ctx Context) bool
- func ParseNumberToken(token string) (float64, bool)
- func QuoteString(s string) (string, error)
- func ValidateString(s string) error
- type Context
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeKey ¶
EncodeKey renders a key, entry key, or field name, quoted unless it may be emitted bare.
func FormatNumber ¶
FormatNumber renders f in canonical number form. Values inside the canonical range use plain decimal notation; outside it, JSON exponent notation with a lowercase "e" and an explicit sign is emitted.
func FormatString ¶
FormatString applies the TOON quoting rules to s.
func IsUnquotedKey ¶
IsUnquotedKey reports whether key may be emitted without quotes.
func NeedsQuoting ¶
NeedsQuoting reports whether s must be quoted.
func ParseNumberToken ¶
ParseNumberToken parses token with the decoder number grammar. The boolean result reports whether the token is a number at all; tokens that are not are plain strings.
func QuoteString ¶
QuoteString escapes s and wraps it in quotes.
func ValidateString ¶
ValidateString rejects host strings that are not sequences of Unicode scalar values. In Go this surfaces as invalid UTF-8, which includes the WTF-8 encoding of an unpaired surrogate.