API
#fmt
Xu 0.8.8 API
import: #fmt
counts: 14 fns, 0 methods, 1 types, 0 consts, 0 ifaces
Formatting: Arg boxing (i/s/b/f/c), sprintf/sprint/print/printf/errorf. Flags -+#0, width, precision. No scanning; no reflection verbs.
struct Arg
pub struct Arg {
pub kind int
pub iv int
pub sv string
pub bv bool
pub fv f64
}
Purpose
Boxed formatting argument. kind selects the payload: 0 int, 1 string, 2 bool, 3 f64, 4 byte/char.
Parameters
kind int- payload tag: 0 int / 1 string / 2 bool / 3 f64 / 4 char
iv int- int or character code (kind 0 or 4)
sv string- string payload (kind 1)
bv bool- bool payload (kind 2)
fv f64- f64 payload (kind 3)
i
Purpose
Box an int as Arg (kind=0).
Parameters
x int- integer to box
Returns
the boxed Arg
s
Purpose
Box a string as Arg (kind=1).
Parameters
x string- string to box
Returns
the boxed Arg
b
Purpose
Box a bool as Arg (kind=2).
Parameters
x bool- bool to box
Returns
the boxed Arg
f
Purpose
Box an f64 as Arg (kind=3).
Parameters
x f64- float to box
Returns
the boxed Arg
c
Purpose
Box a character code (int byte/rune) as Arg (kind=4).
Parameters
x int- character code (int)
Returns
the boxed Arg
sprintf
pub fn sprintf(f string, args <-> Arg) string
Purpose
Build a string from a format string. Flags - + # 0 and space, width, and precision (* consumes an int Arg). Verbs include %v %s %d %b %o %x %X %c %q %f %g and %%. %f/%g/%v without precision use shortest decimal.
Parameters
f string- format string (flags - + # 0, width, precision; as implemented in this package)
args <-> Arg- variadic Arg values (box with fmt.i/s/b/f/c)
Returns
the formatted string
sprintf_args
pub fn sprintf_args(f string, args []Arg) string
Purpose
Same as sprintf, but arguments are a []Arg slice instead of a variadic list.
Parameters
f string- format string (flags - + # 0, width, precision; as implemented in this package)
args []Arg- slice of boxed Arg values
Returns
the formatted string
sprint
pub fn sprint(args <-> Arg) string
Purpose
Format each Arg with the default verb and join with spaces. No trailing newline.
Parameters
args <-> Arg- variadic Arg values (box with fmt.i/s/b/f/c)
Returns
the joined string
sprintln
pub fn sprintln(args <-> Arg) string
Purpose
Same as sprint, with a trailing newline.
Parameters
args <-> Arg- variadic Arg values (box with fmt.i/s/b/f/c)
Returns
the joined string plus a newline
sprint_args
pub fn sprint_args(args []Arg) string
Purpose
Same as sprint, but arguments are a []Arg slice.
Parameters
args []Arg- slice of boxed Arg values
Returns
the joined string
print
pub fn print(args <-> Arg)
Purpose
Print each Arg with the default format. Goes through builtin println, so a trailing newline is written.
Parameters
args <-> Arg- variadic Arg values (box with fmt.i/s/b/f/c)
println
pub fn println(args <-> Arg)
Purpose
Print each Arg with the default format. Goes through builtin println, so a trailing newline is written.
Parameters
args <-> Arg- variadic Arg values (box with fmt.i/s/b/f/c)
printf
pub fn printf(f string, args <-> Arg)
Purpose
Format with a format string and print. Goes through builtin println (trailing newline). On format error, prints the error text.
Parameters
f string- format string (flags - + # 0, width, precision; as implemented in this package)
args <-> Arg- variadic Arg values (box with fmt.i/s/b/f/c)
errorf
pub fn errorf(f string, args <-> Arg) errors.StrErr
Purpose
Build a string from a format string and wrap it as errors.StrErr.
Parameters
f string- format string (flags - + # 0, width, precision; as implemented in this package)
args <-> Arg- variadic Arg values (box with fmt.i/s/b/f/c)
Returns
errors.StrErr whose message is the formatted text