package printf
import "honnef.co/go/tools/printf"
Package printf implements a parser for fmt.Printf-style format strings.
It parses verbs according to the following syntax:
Numeric -> '0'-'9' Letter -> 'a'-'z' | 'A'-'Z' Index -> '[' Numeric+ ']' Star -> '*' Star -> Index '*' Precision -> Numeric+ | Star Width -> Numeric+ | Star WidthAndPrecision -> Width '.' Precision WidthAndPrecision -> Width '.' WidthAndPrecision -> Width WidthAndPrecision -> '.' Precision WidthAndPrecision -> '.' Flag -> '+' | '-' | '#' | ' ' | '0' Verb -> Letter | '%' Input -> '%' [ Flag+ ] [ WidthAndPrecision ] [ Index ] Verb
Index ¶
- Variables
- func Parse(f string) ([]interface{}, error)
- type Argument
- type Default
- type Literal
- type Star
- type Verb
- type Zero
Variables ¶
ErrInvalid is returned for invalid format strings or verbs.
Functions ¶
func Parse ¶
Parse parses f and returns a list of actions. An action may either be a literal string, or a Verb.
Types ¶
type Argument ¶
type Argument interface {
// contains filtered or unexported methods
}
Argument is an implicit or explicit width or precision.
type Default ¶
type Default struct{}
The Default value, when no width or precision is provided.
type Literal ¶
type Literal int
A Literal value, such as 6 in %6d.
type Star ¶
type Star struct{ Index int }
Star is a * value, which may either refer to the next argument (Index == -1) or an explicit argument.
type Verb ¶
type Verb struct { Letter rune Flags string Width Argument Precision Argument // Which value in the argument list the verb uses. // -1 denotes the next argument, // values > 0 denote explicit arguments. // The value 0 denotes that no argument is consumed. This is the case for %%. Value int Raw string }
func ParseVerb ¶
ParseVerb parses the verb at the beginning of f. It returns the verb, how much of the input was consumed, and an error, if any.
type Zero ¶
type Zero struct{}
Zero is the implicit zero value. This value may only appear for precisions in format strings like %6.f
Source Files ¶
printf.go
- Version
- v0.4.0-0.dev
- Published
- Mar 30, 2022
- Platform
- js/wasm
- Imports
- 4 packages
- Last checked
- 7 seconds ago –
Tools for package owners.