Skip to content

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

Closed
@pinpox

Description

@pinpox

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorerror messageThis issue points out an error message that is unhelpful and should be improved.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions