Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two std.fmt fixes #6360

Merged
merged 3 commits into from
Sep 17, 2020
Merged

Two std.fmt fixes #6360

merged 3 commits into from
Sep 17, 2020

Conversation

LemonBoy
Copy link
Contributor

Refer to the individual commits for more info.

Fixes a regression introduced in ziglang#6246.
Adds a test to make sure this won't happen again.
This implementation tries to do the right thing (TM) by treating the
sign as part of the number itself, therefore the alignment parameter
applies to both the sign and the digits.

In other words the format string `{:>4}` with -1 as input will not
output `-  1` but `  -1`.

And let's default to right alignment for everything as that's what users
want, especially when printing numbers. Many implementations use
different defaults for numeric vs non-numeric types, let's strive for a
consistent behaviour here.
@daurnimator daurnimator added the standard library This issue involves writing Zig code for the standard library. label Sep 16, 2020
The two octets in hex notation must be aligned to the right and padded
on the left, not the other way around.
try testFmt(" true", "{:>10}", .{true});
try testFmt("======true", "{:=>10}", .{true});
try testFmt("true======", "{:=<10}", .{true});
try testFmt(" true ", "{:^10}", .{true});
try testFmt("===true===", "{:=^10}", .{true});
try testFmt("Minimum width", "{:18} width", .{"Minimum"});
try testFmt(" Minimum width", "{:18} width", .{"Minimum"});
try testFmt("==================Filled", "{:=>24}", .{"Filled"});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not number, why you break it?

Copy link
Contributor Author

@LemonBoy LemonBoy Sep 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency among data types

@andrewrk andrewrk merged commit 3672a18 into ziglang:master Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants