From 68be2299172f6d87ed5db2ad2a7fcbdef2085725 Mon Sep 17 00:00:00 2001 From: emekoi Date: Sat, 11 Apr 2020 22:30:55 -0500 Subject: added custom format method for WindowsVersion --- lib/std/target.zig | 30 ++++++++++++++++++++++++++++++ lib/std/zig/cross_target.zig | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'lib/std') diff --git a/lib/std/target.zig b/lib/std/target.zig index 9df3e21e52..8edc4acea8 100644 --- a/lib/std/target.zig +++ b/lib/std/target.zig @@ -101,6 +101,36 @@ pub const Target = struct { return @enumToInt(ver) >= @enumToInt(self.min) and @enumToInt(ver) <= @enumToInt(self.max); } }; + + pub fn format( + self: WindowsVersion, + comptime fmt: []const u8, + options: std.fmt.FormatOptions, + out_stream: var, + ) !void { + if (fmt.len > 0 and fmt[0] == 's') { + if ( + @enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.win10_19h1) + ) { + try std.fmt.format(out_stream, ".{}", .{@tagName(self)}); + } else { + try std.fmt.format(out_stream, + "@intToEnum(Target.Os.WindowsVersion, {})", + .{ @enumToInt(self) } + ); + } + } else { + if ( + @enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.win10_19h1) + ) { + try std.fmt.format(out_stream, "WindowsVersion.{}", .{@tagName(self)}); + } else { + try std.fmt.format(out_stream, "WindowsVersion(", .{@typeName(@This())}); + try std.fmt.format(out_stream, "{}", .{@enumToInt(self)}); + try out_stream.writeAll(")"); + } + } + } }; pub const LinuxVersionRange = struct { diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig index 910d263c6a..5466b39f0b 100644 --- a/lib/std/zig/cross_target.zig +++ b/lib/std/zig/cross_target.zig @@ -514,14 +514,14 @@ pub const CrossTarget = struct { switch (self.getOsVersionMin()) { .none => {}, .semver => |v| try result.outStream().print(".{}", .{v}), - .windows => |v| try result.outStream().print(".{}", .{@tagName(v)}), + .windows => |v| try result.outStream().print("{s}", .{v}), } } if (self.os_version_max) |max| { switch (max) { .none => {}, .semver => |v| try result.outStream().print("...{}", .{v}), - .windows => |v| try result.outStream().print("...{}", .{@tagName(v)}), + .windows => |v| try result.outStream().print("..{s}", .{v}), } } -- cgit v1.2.3