| ... | ... | @@ -295,21 +295,21 @@ pub fn format( |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | // Parse the width parameter |
| 298 | | options.width = init: { |
| 299 | | if (comptime parser.maybe('[')) { |
| 300 | | const arg_name = comptime parser.until(']'); |
| 298 | options.width = comptime init: { |
| 299 | if (parser.maybe('[')) { |
| 300 | const arg_name = parser.until(']'); |
| 301 | 301 | |
| 302 | | if (!comptime parser.maybe(']')) { |
| 302 | if (!parser.maybe(']')) { |
| 303 | 303 | @compileError("Expected closing ]"); |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | | const index = comptime meta.fieldIndex(ArgsType, arg_name) orelse |
| 306 | const index = meta.fieldIndex(ArgsType, arg_name) orelse |
| 307 | 307 | @compileError("No argument with name '" ++ arg_name ++ "'"); |
| 308 | | const arg_index = comptime arg_state.nextArg(index); |
| 308 | const arg_index = arg_state.nextArg(index); |
| 309 | 309 | |
| 310 | 310 | break :init @field(args, fields_info[arg_index].name); |
| 311 | 311 | } else { |
| 312 | | break :init comptime parser.number(); |
| 312 | break :init parser.number(); |
| 313 | 313 | } |
| 314 | 314 | }; |
| 315 | 315 | |
| ... | ... | @@ -321,21 +321,21 @@ pub fn format( |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // Parse the precision parameter |
| 324 | | options.precision = init: { |
| 325 | | if (comptime parser.maybe('[')) { |
| 326 | | const arg_name = comptime parser.until(']'); |
| 324 | options.precision = comptime init: { |
| 325 | if (parser.maybe('[')) { |
| 326 | const arg_name = parser.until(']'); |
| 327 | 327 | |
| 328 | | if (!comptime parser.maybe(']')) { |
| 328 | if (!parser.maybe(']')) { |
| 329 | 329 | @compileError("Expected closing ]"); |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | | const arg_i = comptime meta.fieldIndex(ArgsType, arg_name) orelse |
| 332 | const arg_i = meta.fieldIndex(ArgsType, arg_name) orelse |
| 333 | 333 | @compileError("No argument with name '" ++ arg_name ++ "'"); |
| 334 | | const arg_to_use = comptime arg_state.nextArg(arg_i); |
| 334 | const arg_to_use = arg_state.nextArg(arg_i); |
| 335 | 335 | |
| 336 | 336 | break :init @field(args, fields_info[arg_to_use].name); |
| 337 | 337 | } else { |
| 338 | | break :init comptime parser.number(); |
| 338 | break :init parser.number(); |
| 339 | 339 | } |
| 340 | 340 | }; |
| 341 | 341 | |
| ... | ... | @@ -2576,6 +2576,8 @@ test "runtime width specifier" { |
| 2576 | 2576 | var width: usize = 9; |
| 2577 | 2577 | try expectFmt("~~hello~~", "{s:~^[1]}", .{ "hello", width }); |
| 2578 | 2578 | try expectFmt("~~hello~~", "{s:~^[width]}", .{ .string = "hello", .width = width }); |
| 2579 | try expectFmt(" hello", "{s:[1]}", .{ "hello", width }); |
| 2580 | try expectFmt("42 hello", "{d} {s:[2]}", .{ 42, "hello", width }); |
| 2579 | 2581 | } |
| 2580 | 2582 | |
| 2581 | 2583 | test "runtime precision specifier" { |