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

Fix fmt UTF-8 character as fill #18533

Merged
merged 18 commits into from
Jan 14, 2024
Merged

Conversation

vinnichase
Copy link
Sponsor Contributor

@vinnichase vinnichase commented Jan 12, 2024

fixes #17025

I created this PR as a zig learning opportunity.

My changes allowed me to exchange fmt.zig in my project, compile and run it on two platforms with the fill character being correctly formatted.

Of course my changes involve replacing u8s with u21 in various positions which allocates more memory. I clearly don't have the foresight to know if that is against the goals for fmt or causes other problems. I wasn't even sure if I should report a bug until I found the existing one since It is a very narrow edge case only covering one character. Maybe it was even intended to keep it ASCII letters.

However as of now I find it more intuitive to allow all unicode characters.

I'm also happy to discuss implementation details and revise my solution many times 😄

@vinnichase vinnichase changed the title rewrote parser Fix fmt UTF-8 character as fill Jan 12, 2024
Copy link
Contributor

@nektro nektro left a comment

Choose a reason for hiding this comment

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

nice work! please add a test though to be sure and so it doesn't regress :)

jacobly0

This comment was marked as resolved.

@vinnichase
Copy link
Sponsor Contributor Author

vinnichase commented Jan 13, 2024

nice work! please add a test though to be sure and so it doesn't regress :)

Test added. Thanks for feedback!

3 pipelines are green on my fork https://github.com/vinnichase/zig/actions/runs/7510739735
the rest aren't picked up by the runners, however I assume the others to succeed either.

jacobly0

This comment was marked as resolved.

@vinnichase
Copy link
Sponsor Contributor Author

vinnichase commented Jan 13, 2024

To clarify, the issue I was referring to in my previous comment is that the following incorrect program:

OK gotcha! I misunderstood your first suggestion.

This issue needs to be fixed in three places in fmt.Placeholder.parse.

Added your suggested utf8EncodeComptime and invoked it in the three places. Works as you anticipated. Great!

Do we need a test for utf8EncodeComptime?

@jacobly0

This comment was marked as resolved.

lib/std/unicode.zig Outdated Show resolved Hide resolved
lib/std/fmt.zig Outdated Show resolved Hide resolved
lib/std/unicode.zig Outdated Show resolved Hide resolved
vinnichase and others added 2 commits January 13, 2024 10:18
Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
lib/std/unicode.zig Outdated Show resolved Hide resolved
Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
Copy link
Member

@jacobly0 jacobly0 left a comment

Choose a reason for hiding this comment

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

Implementation LGTM

@vinnichase
Copy link
Sponsor Contributor Author

vinnichase commented Jan 13, 2024

@jacobly0

std.debug.print("wow thank you so much for the babysitting! {s:💙<3}\n", .{ "" });

I very much appreciate that. learned some good lessons today.

@andrewrk andrewrk merged commit 279607c into ziglang:master Jan 14, 2024
10 checks passed
bilaliscarioth pushed a commit to bilaliscarioth/zig that referenced this pull request Jan 27, 2024
Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std.fmt.format breaks with UTF-8 character as fill
4 participants