authorgravatar for data-man@users.noreply.github.comDmitry Atamanov <data-man@users.noreply.github.com> 2020-05-26 22:53:51+05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-05-26 20:53:51+03:00
logdd62f63c04fa21427869abea86bbc5fc090b6562
tree756a0a1603f0f2cef1b3b0efebb2ca0d83916b41
parent19a04d8ebd4d671a7f461048555831a629243b49
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

fmt padding correction (#5403)

* Make .Left as default

1 files changed, 2 insertions(+), 3 deletions(-)

lib/std/fmt.zig+2-3
...@@ -17,7 +17,7 @@ pub const Alignment = enum {...@@ -17,7 +17,7 @@ pub const Alignment = enum {
17pub const FormatOptions = struct {17pub const FormatOptions = struct {
18 precision: ?usize = null,18 precision: ?usize = null,
19 width: ?usize = null,19 width: ?usize = null,
20 alignment: ?Alignment = null,20 alignment: Alignment = .Left,
21 fill: u8 = ' ',21 fill: u8 = ' ',
22};22};
2323
...@@ -596,10 +596,9 @@ pub fn formatBuf(...@@ -596,10 +596,9 @@ pub fn formatBuf(
596 out_stream: var,596 out_stream: var,
597) !void {597) !void {
598 const width = options.width orelse buf.len;598 const width = options.width orelse buf.len;
599 const alignment = options.alignment orelse .Left;
600 var padding = if (width > buf.len) (width - buf.len) else 0;599 var padding = if (width > buf.len) (width - buf.len) else 0;
601 const pad_byte = [1]u8{options.fill};600 const pad_byte = [1]u8{options.fill};
602 switch (alignment) {601 switch (options.alignment) {
603 .Left => {602 .Left => {
604 try out_stream.writeAll(buf);603 try out_stream.writeAll(buf);
605 while (padding > 0) : (padding -= 1) {604 while (padding > 0) : (padding -= 1) {