Back to godoc.org
golang.org/x/text/internal/format

package format

v0.3.2
Latest Go to latest
Published: Apr 25, 2019 | License: BSD-3-Clause | Module: golang.org/x/text

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

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
)
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier