Merge pull request #2714 from ziglang/fmt-overhaul
Add positional, precision and width support to std.fmtmaster
commit
f5af349bd6
|
@ -998,7 +998,7 @@ fn printCharValues(out: var, bytes: []const u8) !void {
|
|||
|
||||
fn printUnderstandableChar(out: var, char: u8) !void {
|
||||
if (!std.ascii.isPrint(char) or char == ' ') {
|
||||
std.fmt.format(out.context, anyerror, out.output, "\\x{X2}", char) catch {};
|
||||
std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};
|
||||
} else {
|
||||
try out.write("'");
|
||||
try out.write([_]u8{printable_char_tab[char]});
|
||||
|
|
762
std/fmt.zig
762
std/fmt.zig
File diff suppressed because it is too large
Load Diff
|
@ -519,6 +519,7 @@ pub const Int = struct {
|
|||
pub fn format(
|
||||
self: Int,
|
||||
comptime fmt: []const u8,
|
||||
comptime options: std.fmt.FormatOptions,
|
||||
context: var,
|
||||
comptime FmtError: type,
|
||||
output: fn (@typeOf(context), []const u8) FmtError!void,
|
||||
|
|
|
@ -167,7 +167,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
|
|||
|
||||
const allocator = builder.allocator;
|
||||
for (builder.top_level_steps.toSliceConst()) |top_level_step| {
|
||||
try out_stream.print(" {s22} {}\n", top_level_step.step.name, top_level_step.description);
|
||||
try out_stream.print(" {s:22} {}\n", top_level_step.step.name, top_level_step.description);
|
||||
}
|
||||
|
||||
try out_stream.write(
|
||||
|
@ -188,7 +188,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
|
|||
for (builder.available_options_list.toSliceConst()) |option| {
|
||||
const name = try fmt.allocPrint(allocator, " -D{}=[{}]", option.name, Builder.typeIdName(option.type_id));
|
||||
defer allocator.free(name);
|
||||
try out_stream.print("{s24} {}\n", name, option.description);
|
||||
try out_stream.print("{s:24} {}\n", name, option.description);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
|
|||
\\
|
||||
\\pub fn main() void {
|
||||
\\ const stdout = &(io.getStdOut() catch unreachable).outStream().stream;
|
||||
\\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable;
|
||||
\\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable;
|
||||
\\}
|
||||
, "Hello, world!\n0012 012 a\n");
|
||||
|
||||
|
|
Loading…
Reference in New Issue