XU XUv0.8.8
中文

API

#fmt

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

XuAPI
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

XuAPI
pub fn i(x int) Arg

Purpose

Box an int as Arg (kind=0).

Parameters

x int
integer to box

Returns

the boxed Arg

s

XuAPI
pub fn s(x string) Arg

Purpose

Box a string as Arg (kind=1).

Parameters

x string
string to box

Returns

the boxed Arg

b

XuAPI
pub fn b(x bool) Arg

Purpose

Box a bool as Arg (kind=2).

Parameters

x bool
bool to box

Returns

the boxed Arg

f

XuAPI
pub fn f(x f64) Arg

Purpose

Box an f64 as Arg (kind=3).

Parameters

x f64
float to box

Returns

the boxed Arg

c

XuAPI
pub fn c(x int) Arg

Purpose

Box a character code (int byte/rune) as Arg (kind=4).

Parameters

x int
character code (int)

Returns

the boxed Arg

sprintf

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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

XuAPI
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