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

std.fmt.format breaks with UTF-8 character as fill #17025

Closed
pinpox opened this issue Aug 31, 2023 · 1 comment · Fixed by #18533
Closed

std.fmt.format breaks with UTF-8 character as fill #17025

pinpox opened this issue Aug 31, 2023 · 1 comment · Fixed by #18533
Labels
bug Observed behavior contradicts documented or intended behavior error message This issue points out an error message that is unhelpful and should be improved. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@pinpox
Copy link

pinpox commented Aug 31, 2023

Zig Version

0.11.0

Steps to Reproduce and Observed Behavior

When using some UTF-8 characters to pad/fill the output, print() fails. In the example below, while padding with + signs works as expected, padding with does not. The character is a box drawing character, useful e.g. when drawing tables with text in the terminal.

const std = @import("std");

pub fn main() !void {
    // std.debug.print("{?s:+^20}\n", .{"test"});  // WORKS
    // Output: ++++++++test++++++++ 
    std.debug.print("{?s:─^20}\n", .{"test"}); // DOES NOT WORK
}
❯ zig run main.zig
/nix/store/2rnf5zzshg65zw7g82bph1i1dph2z2r6-zig-0.11.0/lib/zig/std/fmt.zig:268:17: error: expected . or }, found '�
                @compileError("expected . or }, found '" ++ [1]u8{ch} ++ "'");
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/nix/store/2rnf5zzshg65zw7g82bph1i1dph2z2r6-zig-0.11.0/lib/zig/std/fmt.zig:151:55: note: called from here
        const placeholder = comptime Placeholder.parse(fmt[fmt_begin..fmt_end].*);
                                     ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected Behavior

For the padding to work with any printable character.

@pinpox pinpox added the bug Observed behavior contradicts documented or intended behavior label Aug 31, 2023
@pinpox pinpox changed the title std.fmt.format breaks with UTF-8 character as fill std.fmt.format breaks with UTF-8 character as fill Aug 31, 2023
@Vexu Vexu added standard library This issue involves writing Zig code for the standard library. error message This issue points out an error message that is unhelpful and should be improved. labels Nov 29, 2023
@Vexu Vexu added this to the 0.13.0 milestone Nov 29, 2023
@vinnichase
Copy link
Sponsor Contributor

Hey I also encountered this problem when printing tables. I'm a complete newbie to system programming and zig. I took it as a chance to learn more about the inner workings of zig and produced a fix. I'm not expecting an early merge but I'm happy to discuss my implementation and learn about the paradigms of zig.

@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior error message This issue points out an error message that is unhelpful and should be improved. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants