util

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: BSD-1-Clause, BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxInt  = 1<<(IntBits-1) - 1
	MinInt  = -MaxInt - 1
	MaxUint = 1<<IntBits - 1
	IntBits = 1 << (^uint(0)>>32&1 + ^uint(0)>>16&1 + ^uint(0)>>8&1 + 3)
)

Variables

This section is empty.

Functions

func Max

func Max(a, b int) int

Max returns the bigger of a and b

func Min

func Min(a, b int) int

Min returns the smaller of a and b.

Types

type Formatter

type Formatter interface {
	io.Writer
	Format(format string, args ...interface{}) (n int, errno error)
}

Formatter is an io.Writer extended by a fmt.Printf like function Format

func IndentFormatter

func IndentFormatter(w io.Writer, indent string) Formatter

IndentFormatter returns a new Formatter which interprets %i and %u in the Format() format string as indent and undent commands. The commands can nest. The Formatter writes to io.Writer 'w' and inserts one 'indent' string per current indent level value. Behaviour of commands reaching negative indent levels is undefined.

IndentFormatter(os.Stdout, "\t").Format("abc%d%%e%i\nx\ny\n%uz\n", 3)

output:

abc3%e
	x
	y
z

The Go quoted string literal form of the above is:

"abc%%e\n\tx\n\tx\nz\n"

The commands can be scattered between separate invocations of Format(), i.e. the formatter keeps track of the indent level and knows if it is positioned on start of a line and should emit indentation(s). The same output as above can be produced by e.g.:

f := IndentFormatter(os.Stdout, " ")
f.Format("abc%d%%e%i\nx\n", 3)
f.Format("y\n%uz\n")

Jump to

Keyboard shortcuts

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