authorgravatar for benjamin.feng@glassdoor.comBenjamin Feng <benjamin.feng@glassdoor.com> 2020-03-06 08:59:21-06:00
committergravatar for benjamin.feng@glassdoor.comBenjamin Feng <benjamin.feng@glassdoor.com> 2020-03-12 10:41:04-05:00
log0fbccec000efcfe23188027e474530641daf67cd
treea4893c26086659c9c5bf7446de630c20f458f3c3
parentc11d1055b868add74cc58f3bf745e93110ae6071

Convert builtin to fmtstream


1 files changed, 9 insertions(+), 11 deletions(-)

lib/std/builtin.zig+9-11
......@@ -426,29 +426,27 @@ pub const Version = struct {
426426 pub fn parse(text: []const u8) !Version {
427427 var it = std.mem.separate(text, ".");
428428 return Version{
429 .major = try std.fmt.parseInt(u32, it.next() orelse return error.InvalidVersion, 10),
430 .minor = try std.fmt.parseInt(u32, it.next() orelse "0", 10),
431 .patch = try std.fmt.parseInt(u32, it.next() orelse "0", 10),
429 .major = try std.fmtstream.parseInt(u32, it.next() orelse return error.InvalidVersion, 10),
430 .minor = try std.fmtstream.parseInt(u32, it.next() orelse "0", 10),
431 .patch = try std.fmtstream.parseInt(u32, it.next() orelse "0", 10),
432432 };
433433 }
434434
435435 pub fn format(
436436 self: Version,
437437 comptime fmt: []const u8,
438 options: std.fmt.FormatOptions,
439 context: var,
440 comptime Error: type,
441 comptime output: fn (@TypeOf(context), []const u8) Error!void,
442 ) Error!void {
438 options: std.fmtstream.FormatOptions,
439 out_stream: var,
440 ) !void {
443441 if (fmt.len == 0) {
444442 if (self.patch == 0) {
445443 if (self.minor == 0) {
446 return std.fmt.format(context, Error, output, "{}", .{self.major});
444 return std.fmtstream.format(out_stream, "{}", .{self.major});
447445 } else {
448 return std.fmt.format(context, Error, output, "{}.{}", .{ self.major, self.minor });
446 return std.fmtstream.format(out_stream, "{}.{}", .{ self.major, self.minor });
449447 }
450448 } else {
451 return std.fmt.format(context, Error, output, "{}.{}.{}", .{ self.major, self.minor, self.patch });
449 return std.fmtstream.format(out_stream, "{}.{}.{}", .{ self.major, self.minor, self.patch });
452450 }
453451 } else {
454452 @compileError("Unknown format string: '" ++ fmt ++ "'");