format

package
v0.0.0-...-e7e2df9 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package format contains types for defining language-specific formatting of values.

This package is internal now, but will eventually be exposed after the API settles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter interface {
	Format(state State, verb rune)
}

Formatter is analogous to fmt.Formatter.

type Parser

type Parser struct {
	Verb rune

	WidthPresent bool
	PrecPresent  bool
	Minus        bool
	Plus         bool
	Sharp        bool
	Space        bool
	Zero         bool

	// For the formats %+v %#v, we set the plusV/sharpV flags
	// and clear the plus/sharp flags since %+v and %#v are in effect
	// different, flagless formats set at the top level.
	PlusV  bool
	SharpV bool

	HasIndex bool

	Width int
	Prec  int // precision

	// retain arguments across calls.
	Args []interface{}
	// retain current argument number across calls
	ArgNum int

	// reordered records whether the format string used argument reordering.
	Reordered bool

	Status Status
	// contains filtered or unexported fields
}

A Parser parses a format string. The result from the parse are set in the struct fields.

func (*Parser) ClearFlags

func (p *Parser) ClearFlags()

ClearFlags reset the parser to default behavior.

func (*Parser) Reset

func (p *Parser) Reset(args []interface{})

Reset initializes a parser to scan format strings for the given args.

func (*Parser) Scan

func (p *Parser) Scan() bool

Scan scans the next part of the format string and sets the status to indicate whether it scanned a string literal, substitution or error.

func (*Parser) SetFormat

func (p *Parser) SetFormat(format string)

SetFormat sets a new format string to parse. It does not reset the argument count.

func (*Parser) Text

func (p *Parser) Text() string

Text returns the part of the format string that was parsed by the last call to Scan. It returns the original substitution clause if the current scan parsed a substitution.

type State

type State interface {
	fmt.State

	// Language reports the requested language in which to render a message.
	Language() language.Tag
}

State represents the printer state passed to custom formatters. It provides access to the fmt.State interface and the sentence and language-related context.

type Status

type Status int

Status indicates the result type of a call to Scan.

const (
	StatusText Status = iota
	StatusSubstitution
	StatusBadWidthSubstitution
	StatusBadPrecSubstitution
	StatusNoVerb
	StatusBadArgNum
	StatusMissingArg
)

Jump to

Keyboard shortcuts

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