Functions
fn allocPrint(allocator: mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![]u8
No documentation provided.
fn allocPrintZ(allocator: mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8
No documentation provided.
fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![]u8
print a Formatter string into
buf
. Actually just a thin wrapper around `format…print a Formatter string into
buf
. Actually just a thin wrapper aroundformat
andfixedBufferStream
. returns a slice of the bytes printed to.fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, case: Case, options: FormatOptions) []u8
No documentation provided.
fn bufPrintZ(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![:0]u8
No documentation provided.
fn bytesToHex(input: anytype, case: Case) [input.len * 2]u8
Encodes a sequence of bytes as hexadecimal digits. Returns an array containing …
Encodes a sequence of bytes as hexadecimal digits. Returns an array containing the encoded bytes.
inline fn comptimePrint(comptime fmt: []const u8, args: anytype) *const [count(fmt, args):0]u8
No documentation provided.
fn count(comptime fmt: []const u8, args: anytype) u64
Count the characters needed for format. Useful for preallocating memory
fn fmtDuration(ns: u64) Formatter(formatDuration)
Return a Formatter for number of nanoseconds according to its magnitude: [#y][#…
Return a Formatter for number of nanoseconds according to its magnitude: [#y][#w][#d][#h][#m]#[.###][n|u|m]s
fn fmtDurationSigned(ns: i64) Formatter(formatDurationSigned)
Return a Formatter for number of nanoseconds according to its signed magnitude: …
Return a Formatter for number of nanoseconds according to its signed magnitude: [#y][#w][#d][#h][#m]#[.###][n|u|m]s
fn fmtIntSizeBin(value: u64) field_call
Return a Formatter for a u64 value representing a file size. This formatter rep…
Return a Formatter for a u64 value representing a file size. This formatter represents the number as multiple of 1024 and uses the IEC measurement units (KiB, MiB, GiB, …).
fn fmtIntSizeDec(value: u64) field_call
Return a Formatter for a u64 value representing a file size. This formatter rep…
Return a Formatter for a u64 value representing a file size. This formatter represents the number as multiple of 1000 and uses the SI measurement units (kB, MB, GB, …).
fn fmtSliceEscapeLower(bytes: []const u8) field_call
Return a Formatter for a []const u8 where every non-printable ASCII character i…
Return a Formatter for a []const u8 where every non-printable ASCII character is escaped as \xNN, where NN is the character in lowercase hexadecimal notation.
fn fmtSliceEscapeUpper(bytes: []const u8) field_call
Return a Formatter for a []const u8 where every non-printable ASCII character i…
Return a Formatter for a []const u8 where every non-printable ASCII character is escaped as \xNN, where NN is the character in uppercase hexadecimal notation.
fn fmtSliceHexLower(bytes: []const u8) field_call
Return a Formatter for a []const u8 where every byte is formatted as a pair of …
Return a Formatter for a []const u8 where every byte is formatted as a pair of lowercase hexadecimal digits.
fn fmtSliceHexUpper(bytes: []const u8) field_call
Return a Formatter for a []const u8 where every byte is formatted as pair of up…
Return a Formatter for a []const u8 where every byte is formatted as pair of uppercase hexadecimal digits.
fn format(writer: anytype, comptime fmt: []const u8, args: anytype) !void
Renders fmt string with args, calling
writer
with slices of bytes. If `writer…Renders fmt string with args, calling
writer
with slices of bytes. Ifwriter
returns an error, the error is returned fromformat
andwriter
is not called again.The format string must be comptime-known and may contain placeholders following this format:
{[argument][specifier]:[fill][alignment][width].[precision]}
Above, each word including its surrounding [ and ] is a parameter which you have to replace with something:
- argument is either the numeric index or the field name of the argument that should be inserted
- when using a field name, you are required to enclose the field name (an identifier) in square brackets, e.g. {[score]…} as opposed to the numeric index form which can be written e.g. {2…}
- specifier is a type-dependent formatting option that determines how a type should formatted (see below)
- fill is a single character which is used to pad the formatted text
- alignment is one of the three characters
<
,^
, or>
to make the text left-, center-, or right-aligned, respectively - width is the total width of the field in characters
- precision specifies how many decimals a formatted number should have
Note that most of the parameters are optional and may be omitted. Also you can leave out separators like
:
and.
when all parameters after the separator are omitted. Only exception is the fill parameter. If fill is required, one has to specify alignment as well, as otherwise the digits after:
is interpreted as width, not fill.The specifier has several options for types:
x
andX
: output numeric value in hexadecimal notations
:- for pointer-to-many and C pointers of u8, print as a C-string using zero-termination
- for slices of u8, print the entire slice as a string without zero-termination
e
: output floating point value in scientific notationd
: output numeric value in decimal notationb
: output integer value in binary notationo
: output integer value in octal notationc
: output integer as an ASCII character. Integer type must have 8 bits at max.u
: output integer as an UTF-8 sequence. Integer type must have 21 bits at max.?
: output optional value as either the unwrapped value, ornull
; may be followed by a format specifier for the underlying value.!
: output error union value as either the unwrapped value, or the formatted error value; may be followed by a format specifier for the underlying value.*
: output the address of the value instead of the value itself.any
: output a value of any type using its default format.
If a formatted user type contains a function of the type
pub fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void
with
?
being the type formatted, this function will be called instead of the default implementation. This allows user types to be formatted in a logical manner instead of dumping all fields of the type.A user type may be a
struct
,vector
,union
orenum
type.To print literal curly braces, escape them by writing them twice, e.g.
{{
or}}
.- argument is either the numeric index or the field name of the argument that should be inserted
fn formatAddress(value: anytype, options: FormatOptions, writer: anytype) @TypeOf(writer).Error!void
No documentation provided.
fn formatBuf(buf: []const u8, options: FormatOptions, writer: anytype) !void
No documentation provided.
fn formatFloatDecimal(value: anytype, options: FormatOptions, writer: anytype) !void
Print a float of the format x.yyyyy where the number of y is specified by the pr…
Print a float of the format x.yyyyy where the number of y is specified by the precision argument. By default floats are printed at full precision (no rounding).
fn formatFloatHexadecimal(value: anytype, options: FormatOptions, writer: anytype) !void
No documentation provided.
fn formatFloatScientific(value: anytype, options: FormatOptions, writer: anytype) !void
Print a float in scientific notation to the specified precision. Null uses full …
Print a float in scientific notation to the specified precision. Null uses full precision. It should be the case that every full precision, printed value can be re-parsed back to the same type unambiguously.
fn formatInt(value: anytype, base: u8, case: Case, options: FormatOptions, writer: anytype) !void
No documentation provided.
fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, case: Case, options: FormatOptions) usize
No documentation provided.
fn formatIntValue(value: anytype, comptime fmt: []const u8, options: FormatOptions, writer: anytype) !void
No documentation provided.
fn formatText(bytes: []const u8, comptime fmt: []const u8, options: FormatOptions, writer: anytype) !void
No documentation provided.
fn formatType(value: anytype, comptime fmt: []const u8, options: FormatOptions, writer: anytype, max_depth: usize) @TypeOf(writer).Error!void
No documentation provided.
fn formatUnicodeCodepoint(c: u21, options: FormatOptions, writer: anytype) !void
No documentation provided.
fn hexToBytes(out: []u8, input: []const u8) ![]u8
Decodes the sequence of bytes represented by the specified string of hexadecima…
Decodes the sequence of bytes represented by the specified string of hexadecimal characters. Returns a slice of the output buffer containing the decoded bytes.
fn parseInt(comptime T: type, buf: []const u8, base: u8) ParseIntError!T
Parses the string
buf
as signed or unsigned representation in the specified b…Parses the string
buf
as signed or unsigned representation in the specified base of an integral value of typeT
.When
base
is zero the string prefix is examined to detect the true base:- A prefix of “0b” implies base=2,
- A prefix of “0o” implies base=8,
- A prefix of “0x” implies base=16,
- Otherwise base=10 is assumed.
Ignores ‘_’ character in
buf
. See alsoparseUnsigned
.fn parseIntSizeSuffix(buf: []const u8, digit_base: u8) ParseIntError!usize
Parses a number like ‘2G’, ‘2Gi’, or ‘2GiB’.
fn parseUnsigned(comptime T: type, buf: []const u8, base: u8) ParseIntError!T
Parses the string
buf
as unsigned representation in the specified base of an …Parses the string
buf
as unsigned representation in the specified base of an integral value of typeT
.When
base
is zero the string prefix is examined to detect the true base:- A prefix of “0b” implies base=2,
- A prefix of “0o” implies base=8,
- A prefix of “0x” implies base=16,
- Otherwise base=10 is assumed.
Ignores ‘_’ character in
buf
. See alsoparseInt
.