std.fmt: breaking API changes
added adapter to AnyWriter and GenericWriter to help bridge the gap
between old and new API
make std.testing.expectFmt work at compile-time
std.fmt no longer has a dependency on std.unicode. Formatted printing
was never properly unicode-aware. Now it no longer pretends to be.
Breakage/deprecations:
* std.fs.File.reader -> std.fs.File.deprecatedReader
* std.fs.File.writer -> std.fs.File.deprecatedWriter
* std.io.GenericReader -> std.io.Reader
* std.io.GenericWriter -> std.io.Writer
* std.io.AnyReader -> std.io.Reader
* std.io.AnyWriter -> std.io.Writer
* std.fmt.format -> std.fmt.deprecatedFormat
* std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape
* std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape
* std.fmt.fmtSliceHexLower -> {x}
* std.fmt.fmtSliceHexUpper -> {X}
* std.fmt.fmtIntSizeDec -> {B}
* std.fmt.fmtIntSizeBin -> {Bi}
* std.fmt.fmtDuration -> {D}
* std.fmt.fmtDurationSigned -> {D}
* {} -> {f} when there is a format method
* format method signature
- anytype -> *std.io.Writer
- inferred error set -> error{WriteFailed}
- options -> (deleted)
* std.fmt.Formatted
- now takes context type explicitly
- no fmt string
This commit is contained in:
@@ -10,7 +10,7 @@ pub fn main() !void {
|
||||
dir_name, .{});
|
||||
const file_name = args.next().?;
|
||||
const file = try dir.createFile(file_name, .{});
|
||||
try file.writer().print(
|
||||
try file.deprecatedWriter().print(
|
||||
\\{s}
|
||||
\\{s}
|
||||
\\Hello, world!
|
||||
|
||||
@@ -228,7 +228,7 @@ pub fn main() !void {
|
||||
const stdin_file = io.getStdIn();
|
||||
const stdout_file = io.getStdOut();
|
||||
|
||||
const stdin = try stdin_file.reader().readAllAlloc(global_allocator, std.math.maxInt(usize));
|
||||
const stdin = try stdin_file.deprecatedReader().readAllAlloc(global_allocator, std.math.maxInt(usize));
|
||||
defer global_allocator.free(stdin);
|
||||
|
||||
var result_buf = ArrayList(u8).init(global_allocator);
|
||||
|
||||
@@ -58,7 +58,7 @@ pub fn main() !void {
|
||||
std.debug.print(">>> found discrepancy <<<\n", .{});
|
||||
const cmd_line_wtf8 = try std.unicode.wtf16LeToWtf8Alloc(allocator, cmd_line_w);
|
||||
defer allocator.free(cmd_line_wtf8);
|
||||
std.debug.print("\"{}\"\n\n", .{std.zig.fmtEscapes(cmd_line_wtf8)});
|
||||
std.debug.print("\"{f}\"\n\n", .{std.zig.fmtString(cmd_line_wtf8)});
|
||||
|
||||
errors += 1;
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ fn testArgv(expected_args: []const [*:0]const u16) !void {
|
||||
wtf8_buf.clearRetainingCapacity();
|
||||
try std.unicode.wtf16LeToWtf8ArrayList(&wtf8_buf, std.mem.span(expected_arg));
|
||||
if (!std.mem.eql(u8, wtf8_buf.items, arg_wtf8)) {
|
||||
std.debug.print("{}: expected: \"{}\"\n", .{ i, std.zig.fmtEscapes(wtf8_buf.items) });
|
||||
std.debug.print("{}: actual: \"{}\"\n", .{ i, std.zig.fmtEscapes(arg_wtf8) });
|
||||
std.debug.print("{}: expected: \"{f}\"\n", .{ i, std.zig.fmtString(wtf8_buf.items) });
|
||||
std.debug.print("{}: actual: \"{f}\"\n", .{ i, std.zig.fmtString(arg_wtf8) });
|
||||
eql = false;
|
||||
}
|
||||
}
|
||||
@@ -36,22 +36,22 @@ fn testArgv(expected_args: []const [*:0]const u16) !void {
|
||||
for (expected_args[min_len..], min_len..) |arg, i| {
|
||||
wtf8_buf.clearRetainingCapacity();
|
||||
try std.unicode.wtf16LeToWtf8ArrayList(&wtf8_buf, std.mem.span(arg));
|
||||
std.debug.print("{}: expected: \"{}\"\n", .{ i, std.zig.fmtEscapes(wtf8_buf.items) });
|
||||
std.debug.print("{}: expected: \"{f}\"\n", .{ i, std.zig.fmtString(wtf8_buf.items) });
|
||||
}
|
||||
for (args[min_len..], min_len..) |arg, i| {
|
||||
std.debug.print("{}: actual: \"{}\"\n", .{ i, std.zig.fmtEscapes(arg) });
|
||||
std.debug.print("{}: actual: \"{f}\"\n", .{ i, std.zig.fmtString(arg) });
|
||||
}
|
||||
const peb = std.os.windows.peb();
|
||||
const lpCmdLine: [*:0]u16 = @ptrCast(peb.ProcessParameters.CommandLine.Buffer);
|
||||
wtf8_buf.clearRetainingCapacity();
|
||||
try std.unicode.wtf16LeToWtf8ArrayList(&wtf8_buf, std.mem.span(lpCmdLine));
|
||||
std.debug.print("command line: \"{}\"\n", .{std.zig.fmtEscapes(wtf8_buf.items)});
|
||||
std.debug.print("command line: \"{f}\"\n", .{std.zig.fmtString(wtf8_buf.items)});
|
||||
std.debug.print("expected argv:\n", .{});
|
||||
std.debug.print("&.{{\n", .{});
|
||||
for (expected_args) |arg| {
|
||||
wtf8_buf.clearRetainingCapacity();
|
||||
try std.unicode.wtf16LeToWtf8ArrayList(&wtf8_buf, std.mem.span(arg));
|
||||
std.debug.print(" \"{}\",\n", .{std.zig.fmtEscapes(wtf8_buf.items)});
|
||||
std.debug.print(" \"{f}\",\n", .{std.zig.fmtString(wtf8_buf.items)});
|
||||
}
|
||||
std.debug.print("}}\n", .{});
|
||||
return error.ArgvMismatch;
|
||||
|
||||
Reference in New Issue
Block a user