| ... | @@ -69,19 +69,17 @@ fn peekIsAlign(comptime fmt: []const u8) bool { | ... | @@ -69,19 +69,17 @@ fn peekIsAlign(comptime fmt: []const u8) bool { |
| 69 | /// | 69 | /// |
| 70 | /// If a formatted user type contains a function of the type | 70 | /// If a formatted user type contains a function of the type |
| 71 | /// ``` | 71 | /// ``` |
| 72 | /// fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, context: var, comptime Errors: type, comptime output: fn (@TypeOf(context), []const u8) Errors!void) Errors!void | 72 | /// fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: var) !void |
| 73 | /// ``` | 73 | /// ``` |
| 74 | /// with `?` being the type formatted, this function will be called instead of the default implementation. | 74 | /// with `?` being the type formatted, this function will be called instead of the default implementation. |
| 75 | /// This allows user types to be formatted in a logical manner instead of dumping all fields of the type. | 75 | /// This allows user types to be formatted in a logical manner instead of dumping all fields of the type. |
| 76 | /// | 76 | /// |
| 77 | /// A user type may be a `struct`, `vector`, `union` or `enum` type. | 77 | /// A user type may be a `struct`, `vector`, `union` or `enum` type. |
| 78 | pub fn format( | 78 | pub fn format( |
| 79 | context: var, | 79 | out_stream: var, |
| 80 | comptime Errors: type, | | |
| 81 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 82 | comptime fmt: []const u8, | 80 | comptime fmt: []const u8, |
| 83 | args: var, | 81 | args: var, |
| 84 | ) Errors!void { | 82 | ) !void { |
| 85 | const ArgSetType = u32; | 83 | const ArgSetType = u32; |
| 86 | if (@typeInfo(@TypeOf(args)) != .Struct) { | 84 | if (@typeInfo(@TypeOf(args)) != .Struct) { |
| 87 | @compileError("Expected tuple or struct argument, found " ++ @typeName(@TypeOf(args))); | 85 | @compileError("Expected tuple or struct argument, found " ++ @typeName(@TypeOf(args))); |
| ... | @@ -138,7 +136,7 @@ pub fn format( | ... | @@ -138,7 +136,7 @@ pub fn format( |
| 138 | .Start => switch (c) { | 136 | .Start => switch (c) { |
| 139 | '{' => { | 137 | '{' => { |
| 140 | if (start_index < i) { | 138 | if (start_index < i) { |
| 141 | try output(context, fmt[start_index..i]); | 139 | try out_stream.writeAll(fmt[start_index..i]); |
| 142 | } | 140 | } |
| 143 | | 141 | |
| 144 | start_index = i; | 142 | start_index = i; |
| ... | @@ -150,7 +148,7 @@ pub fn format( | ... | @@ -150,7 +148,7 @@ pub fn format( |
| 150 | }, | 148 | }, |
| 151 | '}' => { | 149 | '}' => { |
| 152 | if (start_index < i) { | 150 | if (start_index < i) { |
| 153 | try output(context, fmt[start_index..i]); | 151 | try out_stream.writeAll(fmt[start_index..i]); |
| 154 | } | 152 | } |
| 155 | state = .CloseBrace; | 153 | state = .CloseBrace; |
| 156 | }, | 154 | }, |
| ... | @@ -185,9 +183,7 @@ pub fn format( | ... | @@ -185,9 +183,7 @@ pub fn format( |
| 185 | args[arg_to_print], | 183 | args[arg_to_print], |
| 186 | fmt[0..0], | 184 | fmt[0..0], |
| 187 | options, | 185 | options, |
| 188 | context, | 186 | out_stream, |
| 189 | Errors, | | |
| 190 | output, | | |
| 191 | default_max_depth, | 187 | default_max_depth, |
| 192 | ); | 188 | ); |
| 193 | | 189 | |
| ... | @@ -218,9 +214,7 @@ pub fn format( | ... | @@ -218,9 +214,7 @@ pub fn format( |
| 218 | args[arg_to_print], | 214 | args[arg_to_print], |
| 219 | fmt[specifier_start..i], | 215 | fmt[specifier_start..i], |
| 220 | options, | 216 | options, |
| 221 | context, | 217 | out_stream, |
| 222 | Errors, | | |
| 223 | output, | | |
| 224 | default_max_depth, | 218 | default_max_depth, |
| 225 | ); | 219 | ); |
| 226 | state = .Start; | 220 | state = .Start; |
| ... | @@ -265,9 +259,7 @@ pub fn format( | ... | @@ -265,9 +259,7 @@ pub fn format( |
| 265 | args[arg_to_print], | 259 | args[arg_to_print], |
| 266 | fmt[specifier_start..specifier_end], | 260 | fmt[specifier_start..specifier_end], |
| 267 | options, | 261 | options, |
| 268 | context, | 262 | out_stream, |
| 269 | Errors, | | |
| 270 | output, | | |
| 271 | default_max_depth, | 263 | default_max_depth, |
| 272 | ); | 264 | ); |
| 273 | state = .Start; | 265 | state = .Start; |
| ... | @@ -293,9 +285,7 @@ pub fn format( | ... | @@ -293,9 +285,7 @@ pub fn format( |
| 293 | args[arg_to_print], | 285 | args[arg_to_print], |
| 294 | fmt[specifier_start..specifier_end], | 286 | fmt[specifier_start..specifier_end], |
| 295 | options, | 287 | options, |
| 296 | context, | 288 | out_stream, |
| 297 | Errors, | | |
| 298 | output, | | |
| 299 | default_max_depth, | 289 | default_max_depth, |
| 300 | ); | 290 | ); |
| 301 | state = .Start; | 291 | state = .Start; |
| ... | @@ -316,7 +306,7 @@ pub fn format( | ... | @@ -316,7 +306,7 @@ pub fn format( |
| 316 | } | 306 | } |
| 317 | } | 307 | } |
| 318 | if (start_index < fmt.len) { | 308 | if (start_index < fmt.len) { |
| 319 | try output(context, fmt[start_index..]); | 309 | try out_stream.writeAll(fmt[start_index..]); |
| 320 | } | 310 | } |
| 321 | } | 311 | } |
| 322 | | 312 | |
| ... | @@ -324,141 +314,131 @@ pub fn formatType( | ... | @@ -324,141 +314,131 @@ pub fn formatType( |
| 324 | value: var, | 314 | value: var, |
| 325 | comptime fmt: []const u8, | 315 | comptime fmt: []const u8, |
| 326 | options: FormatOptions, | 316 | options: FormatOptions, |
| 327 | context: var, | 317 | out_stream: var, |
| 328 | comptime Errors: type, | | |
| 329 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 330 | max_depth: usize, | 318 | max_depth: usize, |
| 331 | ) Errors!void { | 319 | ) @TypeOf(out_stream).Error!void { |
| 332 | if (comptime std.mem.eql(u8, fmt, "*")) { | 320 | if (comptime std.mem.eql(u8, fmt, "*")) { |
| 333 | try output(context, @typeName(@TypeOf(value).Child)); | 321 | try out_stream.writeAll(@typeName(@TypeOf(value).Child)); |
| 334 | try output(context, "@"); | 322 | try out_stream.writeAll("@"); |
| 335 | try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, context, Errors, output); | 323 | try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, out_stream); |
| 336 | return; | 324 | return; |
| 337 | } | 325 | } |
| 338 | | 326 | |
| 339 | const T = @TypeOf(value); | 327 | const T = @TypeOf(value); |
| | 328 | if (comptime std.meta.trait.hasFn("format")(T)) { |
| | 329 | return try value.format(fmt, options, out_stream); |
| | 330 | } |
| | 331 | |
| 340 | switch (@typeInfo(T)) { | 332 | switch (@typeInfo(T)) { |
| 341 | .ComptimeInt, .Int, .Float => { | 333 | .ComptimeInt, .Int, .Float => { |
| 342 | return formatValue(value, fmt, options, context, Errors, output); | 334 | return formatValue(value, fmt, options, out_stream); |
| 343 | }, | 335 | }, |
| 344 | .Void => { | 336 | .Void => { |
| 345 | return output(context, "void"); | 337 | return out_stream.writeAll("void"); |
| 346 | }, | 338 | }, |
| 347 | .Bool => { | 339 | .Bool => { |
| 348 | return output(context, if (value) "true" else "false"); | 340 | return out_stream.writeAll(if (value) "true" else "false"); |
| 349 | }, | 341 | }, |
| 350 | .Optional => { | 342 | .Optional => { |
| 351 | if (value) |payload| { | 343 | if (value) |payload| { |
| 352 | return formatType(payload, fmt, options, context, Errors, output, max_depth); | 344 | return formatType(payload, fmt, options, out_stream, max_depth); |
| 353 | } else { | 345 | } else { |
| 354 | return output(context, "null"); | 346 | return out_stream.writeAll("null"); |
| 355 | } | 347 | } |
| 356 | }, | 348 | }, |
| 357 | .ErrorUnion => { | 349 | .ErrorUnion => { |
| 358 | if (value) |payload| { | 350 | if (value) |payload| { |
| 359 | return formatType(payload, fmt, options, context, Errors, output, max_depth); | 351 | return formatType(payload, fmt, options, out_stream, max_depth); |
| 360 | } else |err| { | 352 | } else |err| { |
| 361 | return formatType(err, fmt, options, context, Errors, output, max_depth); | 353 | return formatType(err, fmt, options, out_stream, max_depth); |
| 362 | } | 354 | } |
| 363 | }, | 355 | }, |
| 364 | .ErrorSet => { | 356 | .ErrorSet => { |
| 365 | try output(context, "error."); | 357 | try out_stream.writeAll("error."); |
| 366 | return output(context, @errorName(value)); | 358 | return out_stream.writeAll(@errorName(value)); |
| 367 | }, | 359 | }, |
| 368 | .Enum => |enumInfo| { | 360 | .Enum => |enumInfo| { |
| 369 | if (comptime std.meta.trait.hasFn("format")(T)) { | 361 | try out_stream.writeAll(@typeName(T)); |
| 370 | return value.format(fmt, options, context, Errors, output); | | |
| 371 | } | | |
| 372 | | | |
| 373 | try output(context, @typeName(T)); | | |
| 374 | if (enumInfo.is_exhaustive) { | 362 | if (enumInfo.is_exhaustive) { |
| 375 | try output(context, "."); | 363 | try out_stream.writeAll("."); |
| 376 | try output(context, @tagName(value)); | 364 | try out_stream.writeAll(@tagName(value)); |
| 377 | } else { | 365 | } else { |
| 378 | // TODO: when @tagName works on exhaustive enums print known enum strings | 366 | // TODO: when @tagName works on exhaustive enums print known enum strings |
| 379 | try output(context, "("); | 367 | try out_stream.writeAll("("); |
| 380 | try formatType(@enumToInt(value), fmt, options, context, Errors, output, max_depth); | 368 | try formatType(@enumToInt(value), fmt, options, out_stream, max_depth); |
| 381 | try output(context, ")"); | 369 | try out_stream.writeAll(")"); |
| 382 | } | 370 | } |
| 383 | }, | 371 | }, |
| 384 | .Union => { | 372 | .Union => { |
| 385 | if (comptime std.meta.trait.hasFn("format")(T)) { | 373 | try out_stream.writeAll(@typeName(T)); |
| 386 | return value.format(fmt, options, context, Errors, output); | | |
| 387 | } | | |
| 388 | | | |
| 389 | try output(context, @typeName(T)); | | |
| 390 | if (max_depth == 0) { | 374 | if (max_depth == 0) { |
| 391 | return output(context, "{ ... }"); | 375 | return out_stream.writeAll("{ ... }"); |
| 392 | } | 376 | } |
| 393 | const info = @typeInfo(T).Union; | 377 | const info = @typeInfo(T).Union; |
| 394 | if (info.tag_type) |UnionTagType| { | 378 | if (info.tag_type) |UnionTagType| { |
| 395 | try output(context, "{ ."); | 379 | try out_stream.writeAll("{ ."); |
| 396 | try output(context, @tagName(@as(UnionTagType, value))); | 380 | try out_stream.writeAll(@tagName(@as(UnionTagType, value))); |
| 397 | try output(context, " = "); | 381 | try out_stream.writeAll(" = "); |
| 398 | inline for (info.fields) |u_field| { | 382 | inline for (info.fields) |u_field| { |
| 399 | if (@enumToInt(@as(UnionTagType, value)) == u_field.enum_field.?.value) { | 383 | if (@enumToInt(@as(UnionTagType, value)) == u_field.enum_field.?.value) { |
| 400 | try formatType(@field(value, u_field.name), fmt, options, context, Errors, output, max_depth - 1); | 384 | try formatType(@field(value, u_field.name), fmt, options, out_stream, max_depth - 1); |
| 401 | } | 385 | } |
| 402 | } | 386 | } |
| 403 | try output(context, " }"); | 387 | try out_stream.writeAll(" }"); |
| 404 | } else { | 388 | } else { |
| 405 | try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)}); | 389 | try format(out_stream, "@{x}", .{@ptrToInt(&value)}); |
| 406 | } | 390 | } |
| 407 | }, | 391 | }, |
| 408 | .Struct => |StructT| { | 392 | .Struct => |StructT| { |
| 409 | if (comptime std.meta.trait.hasFn("format")(T)) { | 393 | try out_stream.writeAll(@typeName(T)); |
| 410 | return value.format(fmt, options, context, Errors, output); | | |
| 411 | } | | |
| 412 | | | |
| 413 | try output(context, @typeName(T)); | | |
| 414 | if (max_depth == 0) { | 394 | if (max_depth == 0) { |
| 415 | return output(context, "{ ... }"); | 395 | return out_stream.writeAll("{ ... }"); |
| 416 | } | 396 | } |
| 417 | try output(context, "{"); | 397 | try out_stream.writeAll("{"); |
| 418 | inline for (StructT.fields) |f, i| { | 398 | inline for (StructT.fields) |f, i| { |
| 419 | if (i == 0) { | 399 | if (i == 0) { |
| 420 | try output(context, " ."); | 400 | try out_stream.writeAll(" ."); |
| 421 | } else { | 401 | } else { |
| 422 | try output(context, ", ."); | 402 | try out_stream.writeAll(", ."); |
| 423 | } | 403 | } |
| 424 | try output(context, f.name); | 404 | try out_stream.writeAll(f.name); |
| 425 | try output(context, " = "); | 405 | try out_stream.writeAll(" = "); |
| 426 | try formatType(@field(value, f.name), fmt, options, context, Errors, output, max_depth - 1); | 406 | try formatType(@field(value, f.name), fmt, options, out_stream, max_depth - 1); |
| 427 | } | 407 | } |
| 428 | try output(context, " }"); | 408 | try out_stream.writeAll(" }"); |
| 429 | }, | 409 | }, |
| 430 | .Pointer => |ptr_info| switch (ptr_info.size) { | 410 | .Pointer => |ptr_info| switch (ptr_info.size) { |
| 431 | .One => switch (@typeInfo(ptr_info.child)) { | 411 | .One => switch (@typeInfo(ptr_info.child)) { |
| 432 | .Array => |info| { | 412 | .Array => |info| { |
| 433 | if (info.child == u8) { | 413 | if (info.child == u8) { |
| 434 | return formatText(value, fmt, options, context, Errors, output); | 414 | return formatText(value, fmt, options, out_stream); |
| 435 | } | 415 | } |
| 436 | return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); | 416 | return format(out_stream, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); |
| 437 | }, | 417 | }, |
| 438 | .Enum, .Union, .Struct => { | 418 | .Enum, .Union, .Struct => { |
| 439 | return formatType(value.*, fmt, options, context, Errors, output, max_depth); | 419 | return formatType(value.*, fmt, options, out_stream, max_depth); |
| 440 | }, | 420 | }, |
| 441 | else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }), | 421 | else => return format(out_stream, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }), |
| 442 | }, | 422 | }, |
| 443 | .Many, .C => { | 423 | .Many, .C => { |
| 444 | if (ptr_info.sentinel) |sentinel| { | 424 | if (ptr_info.sentinel) |sentinel| { |
| 445 | return formatType(mem.span(value), fmt, options, context, Errors, output, max_depth); | 425 | return formatType(mem.span(value), fmt, options, out_stream, max_depth); |
| 446 | } | 426 | } |
| 447 | if (ptr_info.child == u8) { | 427 | if (ptr_info.child == u8) { |
| 448 | if (fmt.len > 0 and fmt[0] == 's') { | 428 | if (fmt.len > 0 and fmt[0] == 's') { |
| 449 | return formatText(mem.span(value), fmt, options, context, Errors, output); | 429 | return formatText(mem.span(value), fmt, options, out_stream); |
| 450 | } | 430 | } |
| 451 | } | 431 | } |
| 452 | return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); | 432 | return format(out_stream, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }); |
| 453 | }, | 433 | }, |
| 454 | .Slice => { | 434 | .Slice => { |
| 455 | if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) { | 435 | if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) { |
| 456 | return formatText(value, fmt, options, context, Errors, output); | 436 | return formatText(value, fmt, options, out_stream); |
| 457 | } | 437 | } |
| 458 | if (ptr_info.child == u8) { | 438 | if (ptr_info.child == u8) { |
| 459 | return formatText(value, fmt, options, context, Errors, output); | 439 | return formatText(value, fmt, options, out_stream); |
| 460 | } | 440 | } |
| 461 | return format(context, Errors, output, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) }); | 441 | return format(out_stream, "{}@{x}", .{ @typeName(ptr_info.child), @ptrToInt(value.ptr) }); |
| 462 | }, | 442 | }, |
| 463 | }, | 443 | }, |
| 464 | .Array => |info| { | 444 | .Array => |info| { |
| ... | @@ -473,27 +453,27 @@ pub fn formatType( | ... | @@ -473,27 +453,27 @@ pub fn formatType( |
| 473 | .sentinel = null, | 453 | .sentinel = null, |
| 474 | }, | 454 | }, |
| 475 | }); | 455 | }); |
| 476 | return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth); | 456 | return formatType(@as(Slice, &value), fmt, options, out_stream, max_depth); |
| 477 | }, | 457 | }, |
| 478 | .Vector => { | 458 | .Vector => { |
| 479 | const len = @typeInfo(T).Vector.len; | 459 | const len = @typeInfo(T).Vector.len; |
| 480 | try output(context, "{ "); | 460 | try out_stream.writeAll("{ "); |
| 481 | var i: usize = 0; | 461 | var i: usize = 0; |
| 482 | while (i < len) : (i += 1) { | 462 | while (i < len) : (i += 1) { |
| 483 | try formatValue(value[i], fmt, options, context, Errors, output); | 463 | try formatValue(value[i], fmt, options, out_stream); |
| 484 | if (i < len - 1) { | 464 | if (i < len - 1) { |
| 485 | try output(context, ", "); | 465 | try out_stream.writeAll(", "); |
| 486 | } | 466 | } |
| 487 | } | 467 | } |
| 488 | try output(context, " }"); | 468 | try out_stream.writeAll(" }"); |
| 489 | }, | 469 | }, |
| 490 | .Fn => { | 470 | .Fn => { |
| 491 | return format(context, Errors, output, "{}@{x}", .{ @typeName(T), @ptrToInt(value) }); | 471 | return format(out_stream, "{}@{x}", .{ @typeName(T), @ptrToInt(value) }); |
| 492 | }, | 472 | }, |
| 493 | .Type => return output(context, @typeName(T)), | 473 | .Type => return out_stream.writeAll(@typeName(T)), |
| 494 | .EnumLiteral => { | 474 | .EnumLiteral => { |
| 495 | const buffer = [_]u8{'.'} ++ @tagName(value); | 475 | const buffer = [_]u8{'.'} ++ @tagName(value); |
| 496 | return formatType(buffer, fmt, options, context, Errors, output, max_depth); | 476 | return formatType(buffer, fmt, options, out_stream, max_depth); |
| 497 | }, | 477 | }, |
| 498 | else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"), | 478 | else => @compileError("Unable to format type '" ++ @typeName(T) ++ "'"), |
| 499 | } | 479 | } |
| ... | @@ -503,21 +483,19 @@ fn formatValue( | ... | @@ -503,21 +483,19 @@ fn formatValue( |
| 503 | value: var, | 483 | value: var, |
| 504 | comptime fmt: []const u8, | 484 | comptime fmt: []const u8, |
| 505 | options: FormatOptions, | 485 | options: FormatOptions, |
| 506 | context: var, | 486 | out_stream: var, |
| 507 | comptime Errors: type, | 487 | ) !void { |
| 508 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 509 | ) Errors!void { | | |
| 510 | if (comptime std.mem.eql(u8, fmt, "B")) { | 488 | if (comptime std.mem.eql(u8, fmt, "B")) { |
| 511 | return formatBytes(value, options, 1000, context, Errors, output); | 489 | return formatBytes(value, options, 1000, out_stream); |
| 512 | } else if (comptime std.mem.eql(u8, fmt, "Bi")) { | 490 | } else if (comptime std.mem.eql(u8, fmt, "Bi")) { |
| 513 | return formatBytes(value, options, 1024, context, Errors, output); | 491 | return formatBytes(value, options, 1024, out_stream); |
| 514 | } | 492 | } |
| 515 | | 493 | |
| 516 | const T = @TypeOf(value); | 494 | const T = @TypeOf(value); |
| 517 | switch (@typeInfo(T)) { | 495 | switch (@typeInfo(T)) { |
| 518 | .Float => return formatFloatValue(value, fmt, options, context, Errors, output), | 496 | .Float => return formatFloatValue(value, fmt, options, out_stream), |
| 519 | .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output), | 497 | .Int, .ComptimeInt => return formatIntValue(value, fmt, options, out_stream), |
| 520 | .Bool => return output(context, if (value) "true" else "false"), | 498 | .Bool => return out_stream.writeAll(if (value) "true" else "false"), |
| 521 | else => comptime unreachable, | 499 | else => comptime unreachable, |
| 522 | } | 500 | } |
| 523 | } | 501 | } |
| ... | @@ -526,10 +504,8 @@ pub fn formatIntValue( | ... | @@ -526,10 +504,8 @@ pub fn formatIntValue( |
| 526 | value: var, | 504 | value: var, |
| 527 | comptime fmt: []const u8, | 505 | comptime fmt: []const u8, |
| 528 | options: FormatOptions, | 506 | options: FormatOptions, |
| 529 | context: var, | 507 | out_stream: var, |
| 530 | comptime Errors: type, | 508 | ) !void { |
| 531 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 532 | ) Errors!void { | | |
| 533 | comptime var radix = 10; | 509 | comptime var radix = 10; |
| 534 | comptime var uppercase = false; | 510 | comptime var uppercase = false; |
| 535 | | 511 | |
| ... | @@ -544,7 +520,7 @@ pub fn formatIntValue( | ... | @@ -544,7 +520,7 @@ pub fn formatIntValue( |
| 544 | uppercase = false; | 520 | uppercase = false; |
| 545 | } else if (comptime std.mem.eql(u8, fmt, "c")) { | 521 | } else if (comptime std.mem.eql(u8, fmt, "c")) { |
| 546 | if (@TypeOf(int_value).bit_count <= 8) { | 522 | if (@TypeOf(int_value).bit_count <= 8) { |
| 547 | return formatAsciiChar(@as(u8, int_value), options, context, Errors, output); | 523 | return formatAsciiChar(@as(u8, int_value), options, out_stream); |
| 548 | } else { | 524 | } else { |
| 549 | @compileError("Cannot print integer that is larger than 8 bits as a ascii"); | 525 | @compileError("Cannot print integer that is larger than 8 bits as a ascii"); |
| 550 | } | 526 | } |
| ... | @@ -561,21 +537,19 @@ pub fn formatIntValue( | ... | @@ -561,21 +537,19 @@ pub fn formatIntValue( |
| 561 | @compileError("Unknown format string: '" ++ fmt ++ "'"); | 537 | @compileError("Unknown format string: '" ++ fmt ++ "'"); |
| 562 | } | 538 | } |
| 563 | | 539 | |
| 564 | return formatInt(int_value, radix, uppercase, options, context, Errors, output); | 540 | return formatInt(int_value, radix, uppercase, options, out_stream); |
| 565 | } | 541 | } |
| 566 | | 542 | |
| 567 | fn formatFloatValue( | 543 | fn formatFloatValue( |
| 568 | value: var, | 544 | value: var, |
| 569 | comptime fmt: []const u8, | 545 | comptime fmt: []const u8, |
| 570 | options: FormatOptions, | 546 | options: FormatOptions, |
| 571 | context: var, | 547 | out_stream: var, |
| 572 | comptime Errors: type, | 548 | ) !void { |
| 573 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 574 | ) Errors!void { | | |
| 575 | if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) { | 549 | if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) { |
| 576 | return formatFloatScientific(value, options, context, Errors, output); | 550 | return formatFloatScientific(value, options, out_stream); |
| 577 | } else if (comptime std.mem.eql(u8, fmt, "d")) { | 551 | } else if (comptime std.mem.eql(u8, fmt, "d")) { |
| 578 | return formatFloatDecimal(value, options, context, Errors, output); | 552 | return formatFloatDecimal(value, options, out_stream); |
| 579 | } else { | 553 | } else { |
| 580 | @compileError("Unknown format string: '" ++ fmt ++ "'"); | 554 | @compileError("Unknown format string: '" ++ fmt ++ "'"); |
| 581 | } | 555 | } |
| ... | @@ -585,17 +559,15 @@ pub fn formatText( | ... | @@ -585,17 +559,15 @@ pub fn formatText( |
| 585 | bytes: []const u8, | 559 | bytes: []const u8, |
| 586 | comptime fmt: []const u8, | 560 | comptime fmt: []const u8, |
| 587 | options: FormatOptions, | 561 | options: FormatOptions, |
| 588 | context: var, | 562 | out_stream: var, |
| 589 | comptime Errors: type, | 563 | ) !void { |
| 590 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 591 | ) Errors!void { | | |
| 592 | if (fmt.len == 0) { | 564 | if (fmt.len == 0) { |
| 593 | return output(context, bytes); | 565 | return out_stream.writeAll(bytes); |
| 594 | } else if (comptime std.mem.eql(u8, fmt, "s")) { | 566 | } else if (comptime std.mem.eql(u8, fmt, "s")) { |
| 595 | return formatBuf(bytes, options, context, Errors, output); | 567 | return formatBuf(bytes, options, out_stream); |
| 596 | } else if (comptime (std.mem.eql(u8, fmt, "x") or std.mem.eql(u8, fmt, "X"))) { | 568 | } else if (comptime (std.mem.eql(u8, fmt, "x") or std.mem.eql(u8, fmt, "X"))) { |
| 597 | for (bytes) |c| { | 569 | for (bytes) |c| { |
| 598 | try formatInt(c, 16, fmt[0] == 'X', FormatOptions{ .width = 2, .fill = '0' }, context, Errors, output); | 570 | try formatInt(c, 16, fmt[0] == 'X', FormatOptions{ .width = 2, .fill = '0' }, out_stream); |
| 599 | } | 571 | } |
| 600 | return; | 572 | return; |
| 601 | } else { | 573 | } else { |
| ... | @@ -606,27 +578,23 @@ pub fn formatText( | ... | @@ -606,27 +578,23 @@ pub fn formatText( |
| 606 | pub fn formatAsciiChar( | 578 | pub fn formatAsciiChar( |
| 607 | c: u8, | 579 | c: u8, |
| 608 | options: FormatOptions, | 580 | options: FormatOptions, |
| 609 | context: var, | 581 | out_stream: var, |
| 610 | comptime Errors: type, | 582 | ) !void { |
| 611 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | 583 | return out_stream.writeAll(@as(*const [1]u8, &c)); |
| 612 | ) Errors!void { | | |
| 613 | return output(context, @as(*const [1]u8, &c)[0..]); | | |
| 614 | } | 584 | } |
| 615 | | 585 | |
| 616 | pub fn formatBuf( | 586 | pub fn formatBuf( |
| 617 | buf: []const u8, | 587 | buf: []const u8, |
| 618 | options: FormatOptions, | 588 | options: FormatOptions, |
| 619 | context: var, | 589 | out_stream: var, |
| 620 | comptime Errors: type, | 590 | ) !void { |
| 621 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | 591 | try out_stream.writeAll(buf); |
| 622 | ) Errors!void { | | |
| 623 | try output(context, buf); | | |
| 624 | | 592 | |
| 625 | const width = options.width orelse 0; | 593 | const width = options.width orelse 0; |
| 626 | var leftover_padding = if (width > buf.len) (width - buf.len) else return; | 594 | var leftover_padding = if (width > buf.len) (width - buf.len) else return; |
| 627 | const pad_byte: u8 = options.fill; | 595 | const pad_byte = [1]u8{options.fill}; |
| 628 | while (leftover_padding > 0) : (leftover_padding -= 1) { | 596 | while (leftover_padding > 0) : (leftover_padding -= 1) { |
| 629 | try output(context, @as(*const [1]u8, &pad_byte)[0..1]); | 597 | try out_stream.writeAll(&pad_byte); |
| 630 | } | 598 | } |
| 631 | } | 599 | } |
| 632 | | 600 | |
| ... | @@ -636,40 +604,38 @@ pub fn formatBuf( | ... | @@ -636,40 +604,38 @@ pub fn formatBuf( |
| 636 | pub fn formatFloatScientific( | 604 | pub fn formatFloatScientific( |
| 637 | value: var, | 605 | value: var, |
| 638 | options: FormatOptions, | 606 | options: FormatOptions, |
| 639 | context: var, | 607 | out_stream: var, |
| 640 | comptime Errors: type, | 608 | ) !void { |
| 641 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 642 | ) Errors!void { | | |
| 643 | var x = @floatCast(f64, value); | 609 | var x = @floatCast(f64, value); |
| 644 | | 610 | |
| 645 | // Errol doesn't handle these special cases. | 611 | // Errol doesn't handle these special cases. |
| 646 | if (math.signbit(x)) { | 612 | if (math.signbit(x)) { |
| 647 | try output(context, "-"); | 613 | try out_stream.writeAll("-"); |
| 648 | x = -x; | 614 | x = -x; |
| 649 | } | 615 | } |
| 650 | | 616 | |
| 651 | if (math.isNan(x)) { | 617 | if (math.isNan(x)) { |
| 652 | return output(context, "nan"); | 618 | return out_stream.writeAll("nan"); |
| 653 | } | 619 | } |
| 654 | if (math.isPositiveInf(x)) { | 620 | if (math.isPositiveInf(x)) { |
| 655 | return output(context, "inf"); | 621 | return out_stream.writeAll("inf"); |
| 656 | } | 622 | } |
| 657 | if (x == 0.0) { | 623 | if (x == 0.0) { |
| 658 | try output(context, "0"); | 624 | try out_stream.writeAll("0"); |
| 659 | | 625 | |
| 660 | if (options.precision) |precision| { | 626 | if (options.precision) |precision| { |
| 661 | if (precision != 0) { | 627 | if (precision != 0) { |
| 662 | try output(context, "."); | 628 | try out_stream.writeAll("."); |
| 663 | var i: usize = 0; | 629 | var i: usize = 0; |
| 664 | while (i < precision) : (i += 1) { | 630 | while (i < precision) : (i += 1) { |
| 665 | try output(context, "0"); | 631 | try out_stream.writeAll("0"); |
| 666 | } | 632 | } |
| 667 | } | 633 | } |
| 668 | } else { | 634 | } else { |
| 669 | try output(context, ".0"); | 635 | try out_stream.writeAll(".0"); |
| 670 | } | 636 | } |
| 671 | | 637 | |
| 672 | try output(context, "e+00"); | 638 | try out_stream.writeAll("e+00"); |
| 673 | return; | 639 | return; |
| 674 | } | 640 | } |
| 675 | | 641 | |
| ... | @@ -679,50 +645,50 @@ pub fn formatFloatScientific( | ... | @@ -679,50 +645,50 @@ pub fn formatFloatScientific( |
| 679 | if (options.precision) |precision| { | 645 | if (options.precision) |precision| { |
| 680 | errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Scientific); | 646 | errol.roundToPrecision(&float_decimal, precision, errol.RoundMode.Scientific); |
| 681 | | 647 | |
| 682 | try output(context, float_decimal.digits[0..1]); | 648 | try out_stream.writeAll(float_decimal.digits[0..1]); |
| 683 | | 649 | |
| 684 | // {e0} case prints no `.` | 650 | // {e0} case prints no `.` |
| 685 | if (precision != 0) { | 651 | if (precision != 0) { |
| 686 | try output(context, "."); | 652 | try out_stream.writeAll("."); |
| 687 | | 653 | |
| 688 | var printed: usize = 0; | 654 | var printed: usize = 0; |
| 689 | if (float_decimal.digits.len > 1) { | 655 | if (float_decimal.digits.len > 1) { |
| 690 | const num_digits = math.min(float_decimal.digits.len, precision + 1); | 656 | const num_digits = math.min(float_decimal.digits.len, precision + 1); |
| 691 | try output(context, float_decimal.digits[1..num_digits]); | 657 | try out_stream.writeAll(float_decimal.digits[1..num_digits]); |
| 692 | printed += num_digits - 1; | 658 | printed += num_digits - 1; |
| 693 | } | 659 | } |
| 694 | | 660 | |
| 695 | while (printed < precision) : (printed += 1) { | 661 | while (printed < precision) : (printed += 1) { |
| 696 | try output(context, "0"); | 662 | try out_stream.writeAll("0"); |
| 697 | } | 663 | } |
| 698 | } | 664 | } |
| 699 | } else { | 665 | } else { |
| 700 | try output(context, float_decimal.digits[0..1]); | 666 | try out_stream.writeAll(float_decimal.digits[0..1]); |
| 701 | try output(context, "."); | 667 | try out_stream.writeAll("."); |
| 702 | if (float_decimal.digits.len > 1) { | 668 | if (float_decimal.digits.len > 1) { |
| 703 | const num_digits = if (@TypeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len; | 669 | const num_digits = if (@TypeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len; |
| 704 | | 670 | |
| 705 | try output(context, float_decimal.digits[1..num_digits]); | 671 | try out_stream.writeAll(float_decimal.digits[1..num_digits]); |
| 706 | } else { | 672 | } else { |
| 707 | try output(context, "0"); | 673 | try out_stream.writeAll("0"); |
| 708 | } | 674 | } |
| 709 | } | 675 | } |
| 710 | | 676 | |
| 711 | try output(context, "e"); | 677 | try out_stream.writeAll("e"); |
| 712 | const exp = float_decimal.exp - 1; | 678 | const exp = float_decimal.exp - 1; |
| 713 | | 679 | |
| 714 | if (exp >= 0) { | 680 | if (exp >= 0) { |
| 715 | try output(context, "+"); | 681 | try out_stream.writeAll("+"); |
| 716 | if (exp > -10 and exp < 10) { | 682 | if (exp > -10 and exp < 10) { |
| 717 | try output(context, "0"); | 683 | try out_stream.writeAll("0"); |
| 718 | } | 684 | } |
| 719 | try formatInt(exp, 10, false, FormatOptions{ .width = 0 }, context, Errors, output); | 685 | try formatInt(exp, 10, false, FormatOptions{ .width = 0 }, out_stream); |
| 720 | } else { | 686 | } else { |
| 721 | try output(context, "-"); | 687 | try out_stream.writeAll("-"); |
| 722 | if (exp > -10 and exp < 10) { | 688 | if (exp > -10 and exp < 10) { |
| 723 | try output(context, "0"); | 689 | try out_stream.writeAll("0"); |
| 724 | } | 690 | } |
| 725 | try formatInt(-exp, 10, false, FormatOptions{ .width = 0 }, context, Errors, output); | 691 | try formatInt(-exp, 10, false, FormatOptions{ .width = 0 }, out_stream); |
| 726 | } | 692 | } |
| 727 | } | 693 | } |
| 728 | | 694 | |
| ... | @@ -731,36 +697,34 @@ pub fn formatFloatScientific( | ... | @@ -731,36 +697,34 @@ pub fn formatFloatScientific( |
| 731 | pub fn formatFloatDecimal( | 697 | pub fn formatFloatDecimal( |
| 732 | value: var, | 698 | value: var, |
| 733 | options: FormatOptions, | 699 | options: FormatOptions, |
| 734 | context: var, | 700 | out_stream: var, |
| 735 | comptime Errors: type, | 701 | ) !void { |
| 736 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 737 | ) Errors!void { | | |
| 738 | var x = @as(f64, value); | 702 | var x = @as(f64, value); |
| 739 | | 703 | |
| 740 | // Errol doesn't handle these special cases. | 704 | // Errol doesn't handle these special cases. |
| 741 | if (math.signbit(x)) { | 705 | if (math.signbit(x)) { |
| 742 | try output(context, "-"); | 706 | try out_stream.writeAll("-"); |
| 743 | x = -x; | 707 | x = -x; |
| 744 | } | 708 | } |
| 745 | | 709 | |
| 746 | if (math.isNan(x)) { | 710 | if (math.isNan(x)) { |
| 747 | return output(context, "nan"); | 711 | return out_stream.writeAll("nan"); |
| 748 | } | 712 | } |
| 749 | if (math.isPositiveInf(x)) { | 713 | if (math.isPositiveInf(x)) { |
| 750 | return output(context, "inf"); | 714 | return out_stream.writeAll("inf"); |
| 751 | } | 715 | } |
| 752 | if (x == 0.0) { | 716 | if (x == 0.0) { |
| 753 | try output(context, "0"); | 717 | try out_stream.writeAll("0"); |
| 754 | | 718 | |
| 755 | if (options.precision) |precision| { | 719 | if (options.precision) |precision| { |
| 756 | if (precision != 0) { | 720 | if (precision != 0) { |
| 757 | try output(context, "."); | 721 | try out_stream.writeAll("."); |
| 758 | var i: usize = 0; | 722 | var i: usize = 0; |
| 759 | while (i < precision) : (i += 1) { | 723 | while (i < precision) : (i += 1) { |
| 760 | try output(context, "0"); | 724 | try out_stream.writeAll("0"); |
| 761 | } | 725 | } |
| 762 | } else { | 726 | } else { |
| 763 | try output(context, ".0"); | 727 | try out_stream.writeAll(".0"); |
| 764 | } | 728 | } |
| 765 | } | 729 | } |
| 766 | | 730 | |
| ... | @@ -782,14 +746,14 @@ pub fn formatFloatDecimal( | ... | @@ -782,14 +746,14 @@ pub fn formatFloatDecimal( |
| 782 | | 746 | |
| 783 | if (num_digits_whole > 0) { | 747 | if (num_digits_whole > 0) { |
| 784 | // We may have to zero pad, for instance 1e4 requires zero padding. | 748 | // We may have to zero pad, for instance 1e4 requires zero padding. |
| 785 | try output(context, float_decimal.digits[0..num_digits_whole_no_pad]); | 749 | try out_stream.writeAll(float_decimal.digits[0..num_digits_whole_no_pad]); |
| 786 | | 750 | |
| 787 | var i = num_digits_whole_no_pad; | 751 | var i = num_digits_whole_no_pad; |
| 788 | while (i < num_digits_whole) : (i += 1) { | 752 | while (i < num_digits_whole) : (i += 1) { |
| 789 | try output(context, "0"); | 753 | try out_stream.writeAll("0"); |
| 790 | } | 754 | } |
| 791 | } else { | 755 | } else { |
| 792 | try output(context, "0"); | 756 | try out_stream.writeAll("0"); |
| 793 | } | 757 | } |
| 794 | | 758 | |
| 795 | // {.0} special case doesn't want a trailing '.' | 759 | // {.0} special case doesn't want a trailing '.' |
| ... | @@ -797,7 +761,7 @@ pub fn formatFloatDecimal( | ... | @@ -797,7 +761,7 @@ pub fn formatFloatDecimal( |
| 797 | return; | 761 | return; |
| 798 | } | 762 | } |
| 799 | | 763 | |
| 800 | try output(context, "."); | 764 | try out_stream.writeAll("."); |
| 801 | | 765 | |
| 802 | // Keep track of fractional count printed for case where we pre-pad then post-pad with 0's. | 766 | // Keep track of fractional count printed for case where we pre-pad then post-pad with 0's. |
| 803 | var printed: usize = 0; | 767 | var printed: usize = 0; |
| ... | @@ -809,7 +773,7 @@ pub fn formatFloatDecimal( | ... | @@ -809,7 +773,7 @@ pub fn formatFloatDecimal( |
| 809 | | 773 | |
| 810 | var i: usize = 0; | 774 | var i: usize = 0; |
| 811 | while (i < zeros_to_print) : (i += 1) { | 775 | while (i < zeros_to_print) : (i += 1) { |
| 812 | try output(context, "0"); | 776 | try out_stream.writeAll("0"); |
| 813 | printed += 1; | 777 | printed += 1; |
| 814 | } | 778 | } |
| 815 | | 779 | |
| ... | @@ -821,14 +785,14 @@ pub fn formatFloatDecimal( | ... | @@ -821,14 +785,14 @@ pub fn formatFloatDecimal( |
| 821 | // Remaining fractional portion, zero-padding if insufficient. | 785 | // Remaining fractional portion, zero-padding if insufficient. |
| 822 | assert(precision >= printed); | 786 | assert(precision >= printed); |
| 823 | if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) { | 787 | if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) { |
| 824 | try output(context, float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]); | 788 | try out_stream.writeAll(float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]); |
| 825 | return; | 789 | return; |
| 826 | } else { | 790 | } else { |
| 827 | try output(context, float_decimal.digits[num_digits_whole_no_pad..]); | 791 | try out_stream.writeAll(float_decimal.digits[num_digits_whole_no_pad..]); |
| 828 | printed += float_decimal.digits.len - num_digits_whole_no_pad; | 792 | printed += float_decimal.digits.len - num_digits_whole_no_pad; |
| 829 | | 793 | |
| 830 | while (printed < precision) : (printed += 1) { | 794 | while (printed < precision) : (printed += 1) { |
| 831 | try output(context, "0"); | 795 | try out_stream.writeAll("0"); |
| 832 | } | 796 | } |
| 833 | } | 797 | } |
| 834 | } else { | 798 | } else { |
| ... | @@ -840,14 +804,14 @@ pub fn formatFloatDecimal( | ... | @@ -840,14 +804,14 @@ pub fn formatFloatDecimal( |
| 840 | | 804 | |
| 841 | if (num_digits_whole > 0) { | 805 | if (num_digits_whole > 0) { |
| 842 | // We may have to zero pad, for instance 1e4 requires zero padding. | 806 | // We may have to zero pad, for instance 1e4 requires zero padding. |
| 843 | try output(context, float_decimal.digits[0..num_digits_whole_no_pad]); | 807 | try out_stream.writeAll(float_decimal.digits[0..num_digits_whole_no_pad]); |
| 844 | | 808 | |
| 845 | var i = num_digits_whole_no_pad; | 809 | var i = num_digits_whole_no_pad; |
| 846 | while (i < num_digits_whole) : (i += 1) { | 810 | while (i < num_digits_whole) : (i += 1) { |
| 847 | try output(context, "0"); | 811 | try out_stream.writeAll("0"); |
| 848 | } | 812 | } |
| 849 | } else { | 813 | } else { |
| 850 | try output(context, "0"); | 814 | try out_stream.writeAll("0"); |
| 851 | } | 815 | } |
| 852 | | 816 | |
| 853 | // Omit `.` if no fractional portion | 817 | // Omit `.` if no fractional portion |
| ... | @@ -855,7 +819,7 @@ pub fn formatFloatDecimal( | ... | @@ -855,7 +819,7 @@ pub fn formatFloatDecimal( |
| 855 | return; | 819 | return; |
| 856 | } | 820 | } |
| 857 | | 821 | |
| 858 | try output(context, "."); | 822 | try out_stream.writeAll("."); |
| 859 | | 823 | |
| 860 | // Zero-fill until we reach significant digits or run out of precision. | 824 | // Zero-fill until we reach significant digits or run out of precision. |
| 861 | if (float_decimal.exp < 0) { | 825 | if (float_decimal.exp < 0) { |
| ... | @@ -863,11 +827,11 @@ pub fn formatFloatDecimal( | ... | @@ -863,11 +827,11 @@ pub fn formatFloatDecimal( |
| 863 | | 827 | |
| 864 | var i: usize = 0; | 828 | var i: usize = 0; |
| 865 | while (i < zero_digit_count) : (i += 1) { | 829 | while (i < zero_digit_count) : (i += 1) { |
| 866 | try output(context, "0"); | 830 | try out_stream.writeAll("0"); |
| 867 | } | 831 | } |
| 868 | } | 832 | } |
| 869 | | 833 | |
| 870 | try output(context, float_decimal.digits[num_digits_whole_no_pad..]); | 834 | try out_stream.writeAll(float_decimal.digits[num_digits_whole_no_pad..]); |
| 871 | } | 835 | } |
| 872 | } | 836 | } |
| 873 | | 837 | |
| ... | @@ -875,12 +839,10 @@ pub fn formatBytes( | ... | @@ -875,12 +839,10 @@ pub fn formatBytes( |
| 875 | value: var, | 839 | value: var, |
| 876 | options: FormatOptions, | 840 | options: FormatOptions, |
| 877 | comptime radix: usize, | 841 | comptime radix: usize, |
| 878 | context: var, | 842 | out_stream: var, |
| 879 | comptime Errors: type, | 843 | ) !void { |
| 880 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 881 | ) Errors!void { | | |
| 882 | if (value == 0) { | 844 | if (value == 0) { |
| 883 | return output(context, "0B"); | 845 | return out_stream.writeAll("0B"); |
| 884 | } | 846 | } |
| 885 | | 847 | |
| 886 | const mags_si = " kMGTPEZY"; | 848 | const mags_si = " kMGTPEZY"; |
| ... | @@ -897,10 +859,10 @@ pub fn formatBytes( | ... | @@ -897,10 +859,10 @@ pub fn formatBytes( |
| 897 | else => unreachable, | 859 | else => unreachable, |
| 898 | }; | 860 | }; |
| 899 | | 861 | |
| 900 | try formatFloatDecimal(new_value, options, context, Errors, output); | 862 | try formatFloatDecimal(new_value, options, out_stream); |
| 901 | | 863 | |
| 902 | if (suffix == ' ') { | 864 | if (suffix == ' ') { |
| 903 | return output(context, "B"); | 865 | return out_stream.writeAll("B"); |
| 904 | } | 866 | } |
| 905 | | 867 | |
| 906 | const buf = switch (radix) { | 868 | const buf = switch (radix) { |
| ... | @@ -908,7 +870,7 @@ pub fn formatBytes( | ... | @@ -908,7 +870,7 @@ pub fn formatBytes( |
| 908 | 1024 => &[_]u8{ suffix, 'i', 'B' }, | 870 | 1024 => &[_]u8{ suffix, 'i', 'B' }, |
| 909 | else => unreachable, | 871 | else => unreachable, |
| 910 | }; | 872 | }; |
| 911 | return output(context, buf); | 873 | return out_stream.writeAll(buf); |
| 912 | } | 874 | } |
| 913 | | 875 | |
| 914 | pub fn formatInt( | 876 | pub fn formatInt( |
| ... | @@ -916,10 +878,8 @@ pub fn formatInt( | ... | @@ -916,10 +878,8 @@ pub fn formatInt( |
| 916 | base: u8, | 878 | base: u8, |
| 917 | uppercase: bool, | 879 | uppercase: bool, |
| 918 | options: FormatOptions, | 880 | options: FormatOptions, |
| 919 | context: var, | 881 | out_stream: var, |
| 920 | comptime Errors: type, | 882 | ) !void { |
| 921 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 922 | ) Errors!void { | | |
| 923 | const int_value = if (@TypeOf(value) == comptime_int) blk: { | 883 | const int_value = if (@TypeOf(value) == comptime_int) blk: { |
| 924 | const Int = math.IntFittingRange(value, value); | 884 | const Int = math.IntFittingRange(value, value); |
| 925 | break :blk @as(Int, value); | 885 | break :blk @as(Int, value); |
| ... | @@ -927,9 +887,9 @@ pub fn formatInt( | ... | @@ -927,9 +887,9 @@ pub fn formatInt( |
| 927 | value; | 887 | value; |
| 928 | | 888 | |
| 929 | if (@TypeOf(int_value).is_signed) { | 889 | if (@TypeOf(int_value).is_signed) { |
| 930 | return formatIntSigned(int_value, base, uppercase, options, context, Errors, output); | 890 | return formatIntSigned(int_value, base, uppercase, options, out_stream); |
| 931 | } else { | 891 | } else { |
| 932 | return formatIntUnsigned(int_value, base, uppercase, options, context, Errors, output); | 892 | return formatIntUnsigned(int_value, base, uppercase, options, out_stream); |
| 933 | } | 893 | } |
| 934 | } | 894 | } |
| 935 | | 895 | |
| ... | @@ -938,10 +898,8 @@ fn formatIntSigned( | ... | @@ -938,10 +898,8 @@ fn formatIntSigned( |
| 938 | base: u8, | 898 | base: u8, |
| 939 | uppercase: bool, | 899 | uppercase: bool, |
| 940 | options: FormatOptions, | 900 | options: FormatOptions, |
| 941 | context: var, | 901 | out_stream: var, |
| 942 | comptime Errors: type, | 902 | ) !void { |
| 943 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 944 | ) Errors!void { | | |
| 945 | const new_options = FormatOptions{ | 903 | const new_options = FormatOptions{ |
| 946 | .width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null, | 904 | .width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null, |
| 947 | .precision = options.precision, | 905 | .precision = options.precision, |
| ... | @@ -950,15 +908,15 @@ fn formatIntSigned( | ... | @@ -950,15 +908,15 @@ fn formatIntSigned( |
| 950 | const bit_count = @typeInfo(@TypeOf(value)).Int.bits; | 908 | const bit_count = @typeInfo(@TypeOf(value)).Int.bits; |
| 951 | const Uint = std.meta.IntType(false, bit_count); | 909 | const Uint = std.meta.IntType(false, bit_count); |
| 952 | if (value < 0) { | 910 | if (value < 0) { |
| 953 | try output(context, "-"); | 911 | try out_stream.writeAll("-"); |
| 954 | const new_value = math.absCast(value); | 912 | const new_value = math.absCast(value); |
| 955 | return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output); | 913 | return formatIntUnsigned(new_value, base, uppercase, new_options, out_stream); |
| 956 | } else if (options.width == null or options.width.? == 0) { | 914 | } else if (options.width == null or options.width.? == 0) { |
| 957 | return formatIntUnsigned(@intCast(Uint, value), base, uppercase, options, context, Errors, output); | 915 | return formatIntUnsigned(@intCast(Uint, value), base, uppercase, options, out_stream); |
| 958 | } else { | 916 | } else { |
| 959 | try output(context, "+"); | 917 | try out_stream.writeAll("+"); |
| 960 | const new_value = @intCast(Uint, value); | 918 | const new_value = @intCast(Uint, value); |
| 961 | return formatIntUnsigned(new_value, base, uppercase, new_options, context, Errors, output); | 919 | return formatIntUnsigned(new_value, base, uppercase, new_options, out_stream); |
| 962 | } | 920 | } |
| 963 | } | 921 | } |
| 964 | | 922 | |
| ... | @@ -967,10 +925,8 @@ fn formatIntUnsigned( | ... | @@ -967,10 +925,8 @@ fn formatIntUnsigned( |
| 967 | base: u8, | 925 | base: u8, |
| 968 | uppercase: bool, | 926 | uppercase: bool, |
| 969 | options: FormatOptions, | 927 | options: FormatOptions, |
| 970 | context: var, | 928 | out_stream: var, |
| 971 | comptime Errors: type, | 929 | ) !void { |
| 972 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 973 | ) Errors!void { | | |
| 974 | assert(base >= 2); | 930 | assert(base >= 2); |
| 975 | var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined; | 931 | var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined; |
| 976 | const min_int_bits = comptime math.max(@TypeOf(value).bit_count, @TypeOf(base).bit_count); | 932 | const min_int_bits = comptime math.max(@TypeOf(value).bit_count, @TypeOf(base).bit_count); |
| ... | @@ -994,34 +950,23 @@ fn formatIntUnsigned( | ... | @@ -994,34 +950,23 @@ fn formatIntUnsigned( |
| 994 | const zero_byte: u8 = options.fill; | 950 | const zero_byte: u8 = options.fill; |
| 995 | var leftover_padding = padding - index; | 951 | var leftover_padding = padding - index; |
| 996 | while (true) { | 952 | while (true) { |
| 997 | try output(context, @as(*const [1]u8, &zero_byte)[0..]); | 953 | try out_stream.writeAll(@as(*const [1]u8, &zero_byte)[0..]); |
| 998 | leftover_padding -= 1; | 954 | leftover_padding -= 1; |
| 999 | if (leftover_padding == 0) break; | 955 | if (leftover_padding == 0) break; |
| 1000 | } | 956 | } |
| 1001 | mem.set(u8, buf[0..index], options.fill); | 957 | mem.set(u8, buf[0..index], options.fill); |
| 1002 | return output(context, &buf); | 958 | return out_stream.writeAll(&buf); |
| 1003 | } else { | 959 | } else { |
| 1004 | const padded_buf = buf[index - padding ..]; | 960 | const padded_buf = buf[index - padding ..]; |
| 1005 | mem.set(u8, padded_buf[0..padding], options.fill); | 961 | mem.set(u8, padded_buf[0..padding], options.fill); |
| 1006 | return output(context, padded_buf); | 962 | return out_stream.writeAll(padded_buf); |
| 1007 | } | 963 | } |
| 1008 | } | 964 | } |
| 1009 | | 965 | |
| 1010 | pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) usize { | 966 | pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) usize { |
| 1011 | var context = FormatIntBuf{ | 967 | var fbs = std.io.fixedBufferStream(out_buf); |
| 1012 | .out_buf = out_buf, | 968 | formatInt(value, base, uppercase, options, fbs.outStream()) catch unreachable; |
| 1013 | .index = 0, | 969 | return fbs.pos; |
| 1014 | }; | | |
| 1015 | formatInt(value, base, uppercase, options, &context, error{}, formatIntCallback) catch unreachable; | | |
| 1016 | return context.index; | | |
| 1017 | } | | |
| 1018 | const FormatIntBuf = struct { | | |
| 1019 | out_buf: []u8, | | |
| 1020 | index: usize, | | |
| 1021 | }; | | |
| 1022 | fn formatIntCallback(context: *FormatIntBuf, bytes: []const u8) (error{}!void) { | | |
| 1023 | mem.copy(u8, context.out_buf[context.index..], bytes); | | |
| 1024 | context.index += bytes.len; | | |
| 1025 | } | 970 | } |
| 1026 | | 971 | |
| 1027 | pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T { | 972 | pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T { |
| ... | @@ -1121,44 +1066,36 @@ fn digitToChar(digit: u8, uppercase: bool) u8 { | ... | @@ -1121,44 +1066,36 @@ fn digitToChar(digit: u8, uppercase: bool) u8 { |
| 1121 | }; | 1066 | }; |
| 1122 | } | 1067 | } |
| 1123 | | 1068 | |
| 1124 | const BufPrintContext = struct { | | |
| 1125 | remaining: []u8, | | |
| 1126 | }; | | |
| 1127 | | | |
| 1128 | fn bufPrintWrite(context: *BufPrintContext, bytes: []const u8) !void { | | |
| 1129 | if (context.remaining.len < bytes.len) { | | |
| 1130 | mem.copy(u8, context.remaining, bytes[0..context.remaining.len]); | | |
| 1131 | return error.BufferTooSmall; | | |
| 1132 | } | | |
| 1133 | mem.copy(u8, context.remaining, bytes); | | |
| 1134 | context.remaining = context.remaining[bytes.len..]; | | |
| 1135 | } | | |
| 1136 | | | |
| 1137 | pub const BufPrintError = error{ | 1069 | pub const BufPrintError = error{ |
| 1138 | /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes. | 1070 | /// As much as possible was written to the buffer, but it was too small to fit all the printed bytes. |
| 1139 | BufferTooSmall, | 1071 | NoSpaceLeft, |
| 1140 | }; | 1072 | }; |
| 1141 | pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: var) BufPrintError![]u8 { | 1073 | pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: var) BufPrintError![]u8 { |
| 1142 | var context = BufPrintContext{ .remaining = buf }; | 1074 | var fbs = std.io.fixedBufferStream(buf); |
| 1143 | try format(&context, BufPrintError, bufPrintWrite, fmt, args); | 1075 | try format(fbs.outStream(), fmt, args); |
| 1144 | return buf[0 .. buf.len - context.remaining.len]; | 1076 | return fbs.getWritten(); |
| | 1077 | } |
| | 1078 | |
| | 1079 | // Count the characters needed for format. Useful for preallocating memory |
| | 1080 | pub fn count(comptime fmt: []const u8, args: var) u64 { |
| | 1081 | var counting_stream = std.io.countingOutStream(std.io.null_out_stream); |
| | 1082 | format(counting_stream.outStream(), fmt, args) catch |err| switch (err) {}; |
| | 1083 | return counting_stream.bytes_written; |
| 1145 | } | 1084 | } |
| 1146 | | 1085 | |
| 1147 | pub const AllocPrintError = error{OutOfMemory}; | 1086 | pub const AllocPrintError = error{OutOfMemory}; |
| 1148 | | 1087 | |
| 1149 | pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![]u8 { | 1088 | pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![]u8 { |
| 1150 | var size: usize = 0; | 1089 | const size = math.cast(usize, count(fmt, args)) catch |err| switch (err) { |
| 1151 | format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {}; | 1090 | // Output too long. Can't possibly allocate enough memory to display it. |
| | 1091 | error.Overflow => return error.OutOfMemory, |
| | 1092 | }; |
| 1152 | const buf = try allocator.alloc(u8, size); | 1093 | const buf = try allocator.alloc(u8, size); |
| 1153 | return bufPrint(buf, fmt, args) catch |err| switch (err) { | 1094 | return bufPrint(buf, fmt, args) catch |err| switch (err) { |
| 1154 | error.BufferTooSmall => unreachable, // we just counted the size above | 1095 | error.NoSpaceLeft => unreachable, // we just counted the size above |
| 1155 | }; | 1096 | }; |
| 1156 | } | 1097 | } |
| 1157 | | 1098 | |
| 1158 | fn countSize(size: *usize, bytes: []const u8) (error{}!void) { | | |
| 1159 | size.* += bytes.len; | | |
| 1160 | } | | |
| 1161 | | | |
| 1162 | pub fn allocPrint0(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![:0]u8 { | 1099 | pub fn allocPrint0(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![:0]u8 { |
| 1163 | const result = try allocPrint(allocator, fmt ++ "\x00", args); | 1100 | const result = try allocPrint(allocator, fmt ++ "\x00", args); |
| 1164 | return result[0 .. result.len - 1 :0]; | 1101 | return result[0 .. result.len - 1 :0]; |
| ... | @@ -1251,20 +1188,17 @@ test "int.padded" { | ... | @@ -1251,20 +1188,17 @@ test "int.padded" { |
| 1251 | test "buffer" { | 1188 | test "buffer" { |
| 1252 | { | 1189 | { |
| 1253 | var buf1: [32]u8 = undefined; | 1190 | var buf1: [32]u8 = undefined; |
| 1254 | var context = BufPrintContext{ .remaining = buf1[0..] }; | 1191 | var fbs = std.io.fixedBufferStream(&buf1); |
| 1255 | try formatType(1234, "", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth); | 1192 | try formatType(1234, "", FormatOptions{}, fbs.outStream(), default_max_depth); |
| 1256 | var res = buf1[0 .. buf1.len - context.remaining.len]; | 1193 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "1234")); |
| 1257 | std.testing.expect(mem.eql(u8, res, "1234")); | 1194 | |
| 1258 | | 1195 | fbs.reset(); |
| 1259 | context = BufPrintContext{ .remaining = buf1[0..] }; | 1196 | try formatType('a', "c", FormatOptions{}, fbs.outStream(), default_max_depth); |
| 1260 | try formatType('a', "c", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth); | 1197 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "a")); |
| 1261 | res = buf1[0 .. buf1.len - context.remaining.len]; | 1198 | |
| 1262 | std.testing.expect(mem.eql(u8, res, "a")); | 1199 | fbs.reset(); |
| 1263 | | 1200 | try formatType(0b1100, "b", FormatOptions{}, fbs.outStream(), default_max_depth); |
| 1264 | context = BufPrintContext{ .remaining = buf1[0..] }; | 1201 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "1100")); |
| 1265 | try formatType(0b1100, "b", FormatOptions{}, &context, error{BufferTooSmall}, bufPrintWrite, default_max_depth); | | |
| 1266 | res = buf1[0 .. buf1.len - context.remaining.len]; | | |
| 1267 | std.testing.expect(mem.eql(u8, res, "1100")); | | |
| 1268 | } | 1202 | } |
| 1269 | } | 1203 | } |
| 1270 | | 1204 | |
| ... | @@ -1449,14 +1383,12 @@ test "custom" { | ... | @@ -1449,14 +1383,12 @@ test "custom" { |
| 1449 | self: SelfType, | 1383 | self: SelfType, |
| 1450 | comptime fmt: []const u8, | 1384 | comptime fmt: []const u8, |
| 1451 | options: FormatOptions, | 1385 | options: FormatOptions, |
| 1452 | context: var, | 1386 | out_stream: var, |
| 1453 | comptime Errors: type, | 1387 | ) !void { |
| 1454 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 1455 | ) Errors!void { | | |
| 1456 | if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) { | 1388 | if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) { |
| 1457 | return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y }); | 1389 | return std.fmt.format(out_stream, "({d:.3},{d:.3})", .{ self.x, self.y }); |
| 1458 | } else if (comptime std.mem.eql(u8, fmt, "d")) { | 1390 | } else if (comptime std.mem.eql(u8, fmt, "d")) { |
| 1459 | return std.fmt.format(context, Errors, output, "{d:.3}x{d:.3}", .{ self.x, self.y }); | 1391 | return std.fmt.format(out_stream, "{d:.3}x{d:.3}", .{ self.x, self.y }); |
| 1460 | } else { | 1392 | } else { |
| 1461 | @compileError("Unknown format character: '" ++ fmt ++ "'"); | 1393 | @compileError("Unknown format character: '" ++ fmt ++ "'"); |
| 1462 | } | 1394 | } |
| ... | @@ -1640,10 +1572,10 @@ test "hexToBytes" { | ... | @@ -1640,10 +1572,10 @@ test "hexToBytes" { |
| 1640 | test "formatIntValue with comptime_int" { | 1572 | test "formatIntValue with comptime_int" { |
| 1641 | const value: comptime_int = 123456789123456789; | 1573 | const value: comptime_int = 123456789123456789; |
| 1642 | | 1574 | |
| 1643 | var buf = std.ArrayList(u8).init(std.testing.allocator); | 1575 | var buf: [20]u8 = undefined; |
| 1644 | defer buf.deinit(); | 1576 | var fbs = std.io.fixedBufferStream(&buf); |
| 1645 | try formatIntValue(value, "", FormatOptions{}, &buf, @TypeOf(std.ArrayList(u8).appendSlice).ReturnType.ErrorSet, std.ArrayList(u8).appendSlice); | 1577 | try formatIntValue(value, "", FormatOptions{}, fbs.outStream()); |
| 1646 | std.testing.expect(mem.eql(u8, buf.toSliceConst(), "123456789123456789")); | 1578 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "123456789123456789")); |
| 1647 | } | 1579 | } |
| 1648 | | 1580 | |
| 1649 | test "formatType max_depth" { | 1581 | test "formatType max_depth" { |
| ... | @@ -1656,12 +1588,10 @@ test "formatType max_depth" { | ... | @@ -1656,12 +1588,10 @@ test "formatType max_depth" { |
| 1656 | self: SelfType, | 1588 | self: SelfType, |
| 1657 | comptime fmt: []const u8, | 1589 | comptime fmt: []const u8, |
| 1658 | options: FormatOptions, | 1590 | options: FormatOptions, |
| 1659 | context: var, | 1591 | out_stream: var, |
| 1660 | comptime Errors: type, | 1592 | ) !void { |
| 1661 | comptime output: fn (@TypeOf(context), []const u8) Errors!void, | | |
| 1662 | ) Errors!void { | | |
| 1663 | if (fmt.len == 0) { | 1593 | if (fmt.len == 0) { |
| 1664 | return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y }); | 1594 | return std.fmt.format(out_stream, "({d:.3},{d:.3})", .{ self.x, self.y }); |
| 1665 | } else { | 1595 | } else { |
| 1666 | @compileError("Unknown format string: '" ++ fmt ++ "'"); | 1596 | @compileError("Unknown format string: '" ++ fmt ++ "'"); |
| 1667 | } | 1597 | } |
| ... | @@ -1695,25 +1625,22 @@ test "formatType max_depth" { | ... | @@ -1695,25 +1625,22 @@ test "formatType max_depth" { |
| 1695 | inst.a = &inst; | 1625 | inst.a = &inst; |
| 1696 | inst.tu.ptr = &inst.tu; | 1626 | inst.tu.ptr = &inst.tu; |
| 1697 | | 1627 | |
| 1698 | var buf0 = std.ArrayList(u8).init(std.testing.allocator); | 1628 | var buf: [1000]u8 = undefined; |
| 1699 | defer buf0.deinit(); | 1629 | var fbs = std.io.fixedBufferStream(&buf); |
| 1700 | try formatType(inst, "", FormatOptions{}, &buf0, @TypeOf(std.ArrayList(u8).appendSlice).ReturnType.ErrorSet, std.ArrayList(u8).appendSlice, 0); | 1630 | try formatType(inst, "", FormatOptions{}, fbs.outStream(), 0); |
| 1701 | std.testing.expect(mem.eql(u8, buf0.toSlice(), "S{ ... }")); | 1631 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ ... }")); |
| 1702 | | 1632 | |
| 1703 | var buf1 = std.ArrayList(u8).init(std.testing.allocator); | 1633 | fbs.reset(); |
| 1704 | defer buf1.deinit(); | 1634 | try formatType(inst, "", FormatOptions{}, fbs.outStream(), 1); |
| 1705 | try formatType(inst, "", FormatOptions{}, &buf1, @TypeOf(std.ArrayList(u8).appendSlice).ReturnType.ErrorSet, std.ArrayList(u8).appendSlice, 1); | 1635 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }")); |
| 1706 | std.testing.expect(mem.eql(u8, buf1.toSlice(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }")); | 1636 | |
| 1707 | | 1637 | fbs.reset(); |
| 1708 | var buf2 = std.ArrayList(u8).init(std.testing.allocator); | 1638 | try formatType(inst, "", FormatOptions{}, fbs.outStream(), 2); |
| 1709 | defer buf2.deinit(); | 1639 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }")); |
| 1710 | try formatType(inst, "", FormatOptions{}, &buf2, @TypeOf(std.ArrayList(u8).appendSlice).ReturnType.ErrorSet, std.ArrayList(u8).appendSlice, 2); | 1640 | |
| 1711 | std.testing.expect(mem.eql(u8, buf2.toSlice(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }")); | 1641 | fbs.reset(); |
| 1712 | | 1642 | try formatType(inst, "", FormatOptions{}, fbs.outStream(), 3); |
| 1713 | var buf3 = std.ArrayList(u8).init(std.testing.allocator); | 1643 | std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }")); |
| 1714 | defer buf3.deinit(); | | |
| 1715 | try formatType(inst, "", FormatOptions{}, &buf3, @TypeOf(std.ArrayList(u8).appendSlice).ReturnType.ErrorSet, std.ArrayList(u8).appendSlice, 3); | | |
| 1716 | std.testing.expect(mem.eql(u8, buf3.toSlice(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }")); | | |
| 1717 | } | 1644 | } |
| 1718 | | 1645 | |
| 1719 | test "positional" { | 1646 | test "positional" { |