format

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package format implements the string, key, and number rendering rules of the TOON specification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeKey

func EncodeKey(key string) (string, error)

EncodeKey renders a key, entry key, or field name, quoted unless it may be emitted bare.

func FormatNumber

func FormatNumber(f float64) string

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

func FormatString(s string, ctx Context) (string, error)

FormatString applies the TOON quoting rules to s.

func IsUnquotedKey

func IsUnquotedKey(key string) bool

IsUnquotedKey reports whether key may be emitted without quotes.

func NeedsQuoting

func NeedsQuoting(s string, ctx Context) bool

NeedsQuoting reports whether s must be quoted.

func ParseNumberToken

func ParseNumberToken(token string) (float64, bool)

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

func QuoteString(s string) (string, error)

QuoteString escapes s and wraps it in quotes.

func ValidateString

func ValidateString(s string) error

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.

Types

type Context

type Context struct {
	Delimiter rune
}

Context carries the delimiter that governs delimiter-aware quoting. Conforming encoders declare the document delimiter as the active delimiter of every header they emit, so a single value covers both roles.

Jump to

Keyboard shortcuts

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