| author | |
| committer | |
| log | 11d38a7e520f485206b7b010f64127d864194e4c |
| tree | dd168778189857a4a0d2e7fedce53870a94487b0 |
| parent | 4fdfaf69c8c55ebac4c5b3c00025c0ac51281b5b |
When there are no format parameters, it simply calls `writeAll`. This
has the effect of no longer emitting a compile error for using `{}` and
not having any parameters, however, at this point in the development
process of Zig I think that tradeoff is worthwhile.
On the other hand, it might be OK to simply define formatting to work
this way. It's a common pattern to use the formatting function's format
string `"like this", .{}` instead of `"{}", .{"like this"}`, which can
lead to accidentally putting control characters in the formatting
string, however, with this change that works just fine.1 files changed, 2 insertions(+), 0 deletions(-)
lib/std/fmt.zig+2| ... | @@ -88,6 +88,8 @@ pub fn format( | ... | @@ -88,6 +88,8 @@ pub fn format( |
| 88 | if (args.len > ArgSetType.bit_count) { | 88 | if (args.len > ArgSetType.bit_count) { |
| 89 | @compileError("32 arguments max are supported per format call"); | 89 | @compileError("32 arguments max are supported per format call"); |
| 90 | } | 90 | } |
| 91 | if (args.len == 0) | ||
| 92 | return writer.writeAll(fmt); | ||
| 91 | 93 | ||
| 92 | const State = enum { | 94 | const State = enum { |
| 93 | Start, | 95 | Start, |