Version: v0.0.0-...-7f9930a Latest Latest

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

Go to latest
Published: Sep 6, 2015 License: Apache-2.0 Imports: 2 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type Formatter

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

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

func FlatFormatter

func FlatFormatter(w io.Writer) Formatter

FlatFormatter returns a newly created Formatter with the same functionality as the one returned by IndentFormatter except it allows a newline in the 'format' string argument of Format to pass through if the indent level is current zero.

If the indent level is non-zero then such new lines are changed to a space character. There is no indent string, the %i and %u format verbs are used solely to determine the indent level.

The FlatFormatter is intended for flattening of normally nested structure textual representation to a one top level structure per line form.

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

output in the form of a Go quoted string literal:

"abc3%%e x y z\n"

func IndentFormatter

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

IndentFormatter returns a new Formatter which interprets %i and %u in the Format() formats string as indent and unindent 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)



The Go quoted string literal form of the above is:


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)

Source Files

Jump to

Keyboard shortcuts

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