sprintf

package
v0.0.0-...-3cc3ff2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatJSON

func FormatJSON(store references.Store, tracker references.Tracker, argument *specs.Property) (string, error)

FormatJSON prints provided argument in a JSON format.

func FormatWithFunc

func FormatWithFunc(valueFormatter ValueFormatter) func(Precision) Formatter

FormatWithFunc does common operations (e.g. retrieves scalar value from the reference store).

func Function

func Function(args ...*specs.Property) (*specs.Property, functions.Exec, error)

Function formats and returns a string without printing it anywhere.

Types

type Constant

type Constant string

Constant is a token that does not need any formatting.

func (Constant) String

func (c Constant) String() string

type Constructor

type Constructor interface {
	fmt.Stringer

	TypeChecker

	Formatter(Precision) (Formatter, error)
}

Constructor is a formatter constructor.

type Float

type Float struct{}

Float formatter.

func (Float) CanFormat

func (Float) CanFormat(dataType types.Type) bool

CanFormat checks whether formatter accepts provided data type or not.

func (Float) Formatter

func (fl Float) Formatter(precision Precision) (Formatter, error)

Formatter creates new float formatter.

func (Float) String

func (Float) String() string

type Formatter

type Formatter func(store references.Store, tracker references.Tracker, argument *specs.Property) (string, error)

Formatter is a function to be called in order to format the argument value.

type FormatterDetector

type FormatterDetector interface {
	Detect(input string) (Constructor, bool)
}

FormatterDetector detects formatter (if possible) from provided input.

type Int

type Int struct{}

Int formatter.

func (Int) CanFormat

func (Int) CanFormat(dataType types.Type) bool

CanFormat checks whether formatter accepts provided data type or not.

func (Int) Formatter

func (i Int) Formatter(precision Precision) (Formatter, error)

Formatter creates new float formatter.

func (Int) String

func (Int) String() string

type JSON

type JSON struct{}

JSON formatter.

func (JSON) CanFormat

func (JSON) CanFormat(dataType types.Type) bool

CanFormat checks whether formatter accepts provided data type or not.

func (JSON) Formatter

func (json JSON) Formatter(precision Precision) (Formatter, error)

Formatter validates the presision and returns a JSON formatter.

func (JSON) String

func (JSON) String() string

type Precision

type Precision struct {
	Width int64
	Scale int64
}

Precision is a token which describes the precision and used to create a verb.

func (Precision) String

func (p Precision) String() string

type Printer

type Printer interface {
	Print(store references.Store, args ...*specs.Property) (string, error)
}

Printer compiles the output using argument values.

type Radix

type Radix struct {
	// contains filtered or unexported fields
}

Radix tree based implementation of Formatter registry.

func NewRadix

func NewRadix() *Radix

NewRadix creates new radix tree based Formatter registry.

func (*Radix) Detect

func (r *Radix) Detect(input string) (Constructor, bool)

Detect if input string starts with one of the registered verbs.

func (*Radix) Register

func (r *Radix) Register(constructor Constructor) error

Register provided Formatter.

type Scanner

type Scanner interface {
	Scan(input string) ([]Token, error)
}

Scanner scans provided string splitting it up by tokens.

func NewScanner

func NewScanner(detector FormatterDetector) Scanner

NewScanner creates a stateful scanner with provided formatter detector. Current implementation does not have a state so it can be used concurrently.

type String

type String struct{}

String formatter.

func (String) CanFormat

func (String) CanFormat(dataType types.Type) bool

CanFormat checks whether formatter accepts provided data type or not.

func (String) Formatter

func (str String) Formatter(precision Precision) (Formatter, error)

Formatter creates new string formatter.

func (String) String

func (String) String() string

type Token

type Token interface {
	fmt.Stringer
}

Token represents one of the available tokens.

type Tokens

type Tokens []Token

Tokens is a list of tokens (implements Printer interface).

func (Tokens) Print

func (tokens Tokens) Print(store references.Store, args ...*specs.Property) (string, error)

Print the tokens formatting provided arguments according to the format string.

func (Tokens) Verbs

func (tokens Tokens) Verbs() (verbs []Verb)

Verbs filters and returs tokens of type Verb only.

type TypeChecker

type TypeChecker interface {
	CanFormat(types.Type) bool
}

TypeChecker determines if the provided type can be formatted by the formatter.

type ValueFormatter

type ValueFormatter func(Precision, interface{}) (string, error)

ValueFormatter formats a scalar value with provided precision.

type Verb

type Verb struct {
	TypeChecker
	Verb      string
	Formatter Formatter
}

Verb is a token that is used to print a single input argument.

func (Verb) String

func (v Verb) String() string

Jump to

Keyboard shortcuts

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