Expand description
printf-style formatting
Rust has excellent formatting capabilities, but the coreutils require very
specific formatting that needs to work exactly like the GNU utilities.
Naturally, the GNU behavior is based on the C printf functionality.
Additionally, we need support for escape sequences for the printf utility.
The printf and sprintf functions closely match the behavior of the
corresponding C functions: the former renders a formatted string
to stdout, the latter renders to a new String object.
There are three kinds of parsing that we might want to do:
- Parse only
printfdirectives (for e.g.seq,dd) - Parse only escape sequences (for e.g.
echo) - Parse both
printfspecifiers and escape sequences (for e.g.printf)
This module aims to combine all three use cases. An iterator parsing each
of these cases is provided by parse_spec_only, parse_escape_only
and parse_spec_and_escape, respectively.
There is a special Format type, which can be used to parse a format
string containing exactly one directive and does not use any * in that
directive. This format can be printed in a type-safe manner without failing
(modulo IO errors).
Modules§
- human
human-size formatting- num_
format - Utilities for formatting numbers in various formats
Structs§
- Format
- A format for a single numerical value of type T
- Format
Arguments - A struct that holds a slice of format arguments and provides methods to access them
Enums§
- Escaped
Char - Format
Argument - An argument for formatting
- Format
Error - Format
Item - A single item to format
- Octal
Parsing - Spec
- A parsed specification for formatting a value
Traits§
Functions§
- parse_
escape_ only - Parse a format string containing escape sequences
- parse_
spec_ and_ escape - Parse a format string containing % directives and escape sequences
- parse_
spec_ only - Parse a format string containing % directives
- printf
- Write a formatted string to stdout.
- sprintf
- Create a new formatted string.