| ... | @@ -167,7 +167,8 @@ pub fn format(w: *Writer, comptime fmt: []const u8, args: anytype) Writer.Error! | ... | @@ -167,7 +167,8 @@ pub fn format(w: *Writer, comptime fmt: []const u8, args: anytype) Writer.Error! |
| 167 | comptime assert(fmt[i] == '}'); | 167 | comptime assert(fmt[i] == '}'); |
| 168 | i += 1; | 168 | i += 1; |
| 169 | | 169 | |
| 170 | const placeholder = comptime Placeholder.parse(&(fmt[fmt_begin..fmt_end].*)); | 170 | const placeholder_array = fmt[fmt_begin..fmt_end].*; |
| | 171 | const placeholder = comptime Placeholder.parse(&placeholder_array); |
| 171 | const arg_pos = comptime switch (placeholder.arg) { | 172 | const arg_pos = comptime switch (placeholder.arg) { |
| 172 | .none => null, | 173 | .none => null, |
| 173 | .number => |pos| pos, | 174 | .number => |pos| pos, |
| ... | @@ -231,10 +232,6 @@ pub fn deprecatedFormat(writer: anytype, comptime fmt: []const u8, args: anytype | ... | @@ -231,10 +232,6 @@ pub fn deprecatedFormat(writer: anytype, comptime fmt: []const u8, args: anytype |
| 231 | }; | 232 | }; |
| 232 | } | 233 | } |
| 233 | | 234 | |
| 234 | fn cacheString(str: anytype) []const u8 { | | |
| 235 | return &str; | | |
| 236 | } | | |
| 237 | | | |
| 238 | pub const Placeholder = struct { | 235 | pub const Placeholder = struct { |
| 239 | specifier_arg: []const u8, | 236 | specifier_arg: []const u8, |
| 240 | fill: u8, | 237 | fill: u8, |
| ... | @@ -243,7 +240,7 @@ pub const Placeholder = struct { | ... | @@ -243,7 +240,7 @@ pub const Placeholder = struct { |
| 243 | width: Specifier, | 240 | width: Specifier, |
| 244 | precision: Specifier, | 241 | precision: Specifier, |
| 245 | | 242 | |
| 246 | pub fn parse(bytes: []const u8) Placeholder { | 243 | pub fn parse(comptime bytes: []const u8) Placeholder { |
| 247 | var parser: Parser = .{ .bytes = bytes, .i = 0 }; | 244 | var parser: Parser = .{ .bytes = bytes, .i = 0 }; |
| 248 | const arg = parser.specifier() catch |err| @compileError(@errorName(err)); | 245 | const arg = parser.specifier() catch |err| @compileError(@errorName(err)); |
| 249 | const specifier_arg = parser.until(':'); | 246 | const specifier_arg = parser.until(':'); |
| ... | @@ -298,8 +295,10 @@ pub const Placeholder = struct { | ... | @@ -298,8 +295,10 @@ pub const Placeholder = struct { |
| 298 | | 295 | |
| 299 | if (parser.char()) |b| @compileError("extraneous trailing character '" ++ &[1]u8{b} ++ "'"); | 296 | if (parser.char()) |b| @compileError("extraneous trailing character '" ++ &[1]u8{b} ++ "'"); |
| 300 | | 297 | |
| | 298 | const specifier_array = specifier_arg[0..specifier_arg.len].*; |
| | 299 | |
| 301 | return .{ | 300 | return .{ |
| 302 | .specifier_arg = cacheString(specifier_arg[0..specifier_arg.len].*), | 301 | .specifier_arg = &specifier_array, |
| 303 | .fill = fill orelse default_fill_char, | 302 | .fill = fill orelse default_fill_char, |
| 304 | .alignment = alignment orelse default_alignment, | 303 | .alignment = alignment orelse default_alignment, |
| 305 | .arg = arg, | 304 | .arg = arg, |