printf

package
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2019 License: MIT, MIT Imports: 4 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

View Source
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

Jump to

Keyboard shortcuts

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