# format: do not force user to provide an alignment field when it's not necessary \(\#19049\) · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/c3faae6bf1589380e983aaf9e3238f053ba4a674)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: c3faae6bf1589380e983aaf9e3238f053ba4a674

Requested commit: c3faae6bf1589380e983aaf9e3238f053ba4a674

Commit: c3faae6bf1589380e983aaf9e3238f053ba4a674

Tree: 4f6fe3d65daa3aa81cf08f150e26aadd12ac01b0

Author: eric-saintetienne

Committer: GitHub

## Message

```
format: do not force user to provide an alignment field when it's not necessary (#19049)

* format: fix default character when no alignment

When no alignment is specified, the character that should be used is the
fill character that is otherwise provided, not space.

This is closer to the default that C programmers (and other languages)
use: "04x" fills with zeroes (in zig as of today x:04 fills with spaces)

Test:

    const std = @import("std");
    const expectFmt = std.testing.expectFmt;

    test "fmt.defaultchar.no-alignment" {

        // as of today the following test passes:
        try expectFmt("0x00ff", "0x{x:0>4}", .{255});

        // as of today the following test fails (returns "0x  ff" instead)
        try expectFmt("0x00ff", "0x{x:04}", .{255});
    }

* non breaking improvement of string formatting

* improved comment

* simplify the code a little

* small improvement around how  characters identified as valid are consumed
```

## Parents

- [9d9b5a11e873cc15e3f1b6e506ecf22c8380c87d](https://git.cafe/gitcafe/zig/commit/9d9b5a11e873cc15e3f1b6e506ecf22c8380c87d?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/c3faae6bf1589380e983aaf9e3238f053ba4a674?format=markdown)
