text: golang.org/x/text/internal/format Index | Files

package format

import "golang.org/x/text/internal/format"

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

Package Files

format.go parser.go

type Formatter Uses

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

Formatter is analogous to fmt.Formatter.

type Parser Uses

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 Uses

func (p *Parser) ClearFlags()

ClearFlags reset the parser to default behavior.

func (*Parser) Reset Uses

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

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

func (*Parser) Scan Uses

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 Uses

func (p *Parser) SetFormat(format string)

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

func (*Parser) Text Uses

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 Uses

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 Uses

type Status int

Status indicates the result type of a call to Scan.

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

Package format imports 4 packages (graph) and is imported by 7 packages. Updated 2017-12-16. Refresh now. Tools for package owners.