toolshonnef.co/go/tools/printf Index | Files

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

var ErrInvalid = errors.New("invalid format string")

ErrInvalid is returned for invalid format strings or verbs.

Functions

func Parse

func Parse(f string) ([]interface{}, error)

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

func ParseVerb(f string) (Verb, int, error)

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.2.0-0.dev
Published
Dec 14, 2020
Platform
windows/amd64
Imports
4 packages
Last checked
1 minute ago

Tools for package owners.