fmt padding correction (#5403)

* Make .Left as default
This commit is contained in:
Dmitry Atamanov 2020-05-26 22:53:51 +05:00 committed by GitHub
parent 19a04d8ebd
commit dd62f63c04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,7 @@ pub const Alignment = enum {
pub const FormatOptions = struct {
precision: ?usize = null,
width: ?usize = null,
alignment: ?Alignment = null,
alignment: Alignment = .Left,
fill: u8 = ' ',
};
@ -596,10 +596,9 @@ pub fn formatBuf(
out_stream: var,
) !void {
const width = options.width orelse buf.len;
const alignment = options.alignment orelse .Left;
var padding = if (width > buf.len) (width - buf.len) else 0;
const pad_byte = [1]u8{options.fill};
switch (alignment) {
switch (options.alignment) {
.Left => {
try out_stream.writeAll(buf);
while (padding > 0) : (padding -= 1) {