| ... | ... | @@ -11,7 +11,10 @@ const max_int_digits = 65; |
| 11 | 11 | /// Renders fmt string with args, calling output with slices of bytes. |
| 12 | 12 | /// If `output` returns an error, the error is returned from `format` and |
| 13 | 13 | /// `output` is not called again. |
| 14 | | pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: ...) Errors!void { |
| 14 | pub fn format(context: var, comptime Errors: type, |
| 15 | output: fn(@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, |
| 16 | args: ...) Errors!void |
| 17 | { |
| 15 | 18 | const State = enum { |
| 16 | 19 | Start, |
| 17 | 20 | OpenBrace, |
| ... | ... | @@ -281,7 +284,9 @@ pub fn formatText(bytes: []const u8, comptime fmt: []const u8, context: var, |
| 281 | 284 | return output(context, bytes); |
| 282 | 285 | } |
| 283 | 286 | |
| 284 | | pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { |
| 287 | pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, |
| 288 | output: fn(@typeOf(context), []const u8) Errors!void) Errors!void |
| 289 | { |
| 285 | 290 | return output(context, (&c)[0..1]); |
| 286 | 291 | } |
| 287 | 292 | |
| ... | ... | @@ -300,7 +305,9 @@ pub fn formatBuf(buf: []const u8, width: usize, context: var, |
| 300 | 305 | // Print a float in scientific notation to the specified precision. Null uses full precision. |
| 301 | 306 | // It should be the case that every full precision, printed value can be re-parsed back to the |
| 302 | 307 | // same type unambiguously. |
| 303 | | pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { |
| 308 | pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, |
| 309 | comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void |
| 310 | { |
| 304 | 311 | var x = f64(value); |
| 305 | 312 | |
| 306 | 313 | // Errol doesn't handle these special cases. |
| ... | ... | @@ -389,7 +396,9 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, |
| 389 | 396 | |
| 390 | 397 | // Print a float of the format x.yyyyy where the number of y is specified by the precision argument. |
| 391 | 398 | // By default floats are printed at full precision (no rounding). |
| 392 | | pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { |
| 399 | pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, |
| 400 | output: fn(@typeOf(context), []const u8) Errors!void) Errors!void |
| 401 | { |
| 393 | 402 | var x = f64(value); |
| 394 | 403 | |
| 395 | 404 | // Errol doesn't handle these special cases. |
| ... | ... | @@ -579,7 +588,9 @@ pub fn formatInt( |
| 579 | 588 | } |
| 580 | 589 | } |
| 581 | 590 | |
| 582 | | fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { |
| 591 | fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: var, |
| 592 | comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void |
| 593 | { |
| 583 | 594 | const uint = @IntType(false, @typeOf(value).bit_count); |
| 584 | 595 | if (value < 0) { |
| 585 | 596 | const minus_sign: u8 = '-'; |
| ... | ... | @@ -598,7 +609,9 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: |
| 598 | 609 | } |
| 599 | 610 | } |
| 600 | 611 | |
| 601 | | fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { |
| 612 | fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, context: var, |
| 613 | comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void |
| 614 | { |
| 602 | 615 | // max_int_digits accounts for the minus sign. when printing an unsigned |
| 603 | 616 | // number we don't need to do that. |
| 604 | 617 | var buf: [max_int_digits - 1]u8 = undefined; |