| ... | @@ -3,6 +3,7 @@ | ... | @@ -3,6 +3,7 @@ |
| 3 | const std = @import("std"); | 3 | const std = @import("std"); |
| 4 | const builtin = @import("builtin"); | 4 | const builtin = @import("builtin"); |
| 5 | const extras = @import("extras"); | 5 | const extras = @import("extras"); |
| | 6 | const nio = @import("./nio.zig"); |
| 6 | | 7 | |
| 7 | /// Renders fmt string with args, calling `writer` with slices of bytes. | 8 | /// Renders fmt string with args, calling `writer` with slices of bytes. |
| 8 | /// If `writer` returns an error, the error is returned from `format` and | 9 | /// If `writer` returns an error, the error is returned from `format` and |
| ... | @@ -808,20 +809,20 @@ fn formatBuf(buf: []const u8, options: FormatOptions, writer: anytype) !void { | ... | @@ -808,20 +809,20 @@ fn formatBuf(buf: []const u8, options: FormatOptions, writer: anytype) !void { |
| 808 | | 809 | |
| 809 | /// Count the characters needed for format. Useful for preallocating memory | 810 | /// Count the characters needed for format. Useful for preallocating memory |
| 810 | fn count(comptime fmt: []const u8, args: anytype) u64 { | 811 | fn count(comptime fmt: []const u8, args: anytype) u64 { |
| 811 | var counting_writer = std.io.countingWriter(std.io.null_writer); | 812 | var counting_writer: nio.CountingWriter(nio.NullWriter) = .init(.{}); |
| 812 | format(counting_writer.writer().any(), fmt, args) catch unreachable; | 813 | format(&counting_writer, fmt, args) catch unreachable; |
| 813 | return counting_writer.bytes_written; | 814 | return counting_writer.bytes_written; |
| 814 | } | 815 | } |
| 815 | | 816 | |
| 816 | /// Print a Formatter string into `buf`. Actually just a thin wrapper around `format` and `fixedBufferStream`. | 817 | /// Print a Formatter string into `buf`. Actually just a thin wrapper around `format` and `fixedBufferStream`. |
| 817 | /// Returns a slice of the bytes printed to. | 818 | /// Returns a slice of the bytes printed to. |
| 818 | fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) ![]u8 { | 819 | fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) ![]u8 { |
| 819 | var fbs = std.io.fixedBufferStream(buf); | 820 | var fbs: nio.FixedBufferStream([]u8) = .init(buf); |
| 820 | format(fbs.writer().any(), fmt, args) catch |err| switch (err) { | 821 | format(&fbs, fmt, args) catch |err| switch (err) { |
| 821 | error.NoSpaceLeft => return error.NoSpaceLeft, | 822 | error.NoSpaceLeft => return error.NoSpaceLeft, |
| 822 | else => unreachable, | 823 | else => unreachable, |
| 823 | }; | 824 | }; |
| 824 | return fbs.getWritten(); | 825 | return fbs.written(); |
| 825 | } | 826 | } |
| 826 | | 827 | |
| 827 | const digits2_alphabet = blk: { | 828 | const digits2_alphabet = blk: { |
| ... | @@ -920,11 +921,11 @@ fn formatFloatValue(value: anytype, comptime fmt: []const u8, options: FormatOpt | ... | @@ -920,11 +921,11 @@ fn formatFloatValue(value: anytype, comptime fmt: []const u8, options: FormatOpt |
| 920 | }; | 921 | }; |
| 921 | return formatBuf(s, options, writer); | 922 | return formatBuf(s, options, writer); |
| 922 | } else if (comptime std.mem.eql(u8, fmt, "x")) { | 923 | } else if (comptime std.mem.eql(u8, fmt, "x")) { |
| 923 | var buf_stream = std.io.fixedBufferStream(&buf); | 924 | var buf_stream: nio.FixedBufferStream([]u8) = .init(&buf); |
| 924 | std.fmt.formatFloatHexadecimal(value, options, buf_stream.writer()) catch |err| switch (err) { | 925 | std.fmt.formatFloatHexadecimal(value, options, &buf_stream) catch |err| switch (err) { |
| 925 | error.NoSpaceLeft => unreachable, | 926 | error.NoSpaceLeft => unreachable, |
| 926 | }; | 927 | }; |
| 927 | return formatBuf(buf_stream.getWritten(), options, writer); | 928 | return formatBuf(buf_stream.written(), options, writer); |
| 928 | } else { | 929 | } else { |
| 929 | invalidFmtError(fmt, value); | 930 | invalidFmtError(fmt, value); |
| 930 | } | 931 | } |