Skip to content

std.fmt c specifier should print numbers as unicode codepoints #5564

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

Closed
Vexu opened this issue Jun 8, 2020 · 2 comments
Closed

std.fmt c specifier should print numbers as unicode codepoints #5564

Vexu opened this issue Jun 8, 2020 · 2 comments
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@Vexu
Copy link
Member

Vexu commented Jun 8, 2020

It makes no sense to have unicode character literals but no way to format them.

test "" {
    @import("std").debug.warn("{c}\n", .{'あ'});
    // error: Cannot print integer that is larger than 8 bits as a ascii
}

The c specifier should format integers as unicode codepoints and a new specifier should be added for formatting them as their literal bytes.

This is how the Go, Python, Odin and Java handle c.

@Vexu Vexu added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. standard library This issue involves writing Zig code for the standard library. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. labels Jun 8, 2020
@Vexu Vexu added this to the 0.7.0 milestone Jun 8, 2020
@data-man
Copy link
Contributor

data-man commented Jun 9, 2020

In #3970 I proposed 'u'.

u: output integer as an UTF-8 sequence. Integer type must have 21 bits at max.

But I prefer U+FFFD for invalid codepoints.

https://en.wikipedia.org/wiki/UTF-8#Invalid_byte_sequences

The standard also recommends replacing each error with the replacement character "�" (U+FFFD).

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@andrewrk
Copy link
Member

Implemented by @LemonBoy in #6390, landed in 473cb1f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

3 participants