This repository has been archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaskedVersion.swift
72 lines (67 loc) · 2.07 KB
/
MaskedVersion.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import Grammar
@frozen public
enum MaskedVersion:Hashable, CustomStringConvertible, Sendable
{
// static
// func semantic(_ version:(major:UInt16, minor:UInt16, patch:UInt16, edition:UInt16))
// -> Self
// {
// .edition(version.major, version.minor, version.patch, version.edition)
// }
case major(UInt16)
case minor(UInt16, UInt16)
case patch(UInt16, UInt16, UInt16)
case edition(UInt16, UInt16, UInt16, UInt16)
case nightly(year:UInt16, month:UInt16, day:UInt16)
case hourly(year:UInt16, month:UInt16, day:UInt16, letter:UInt8)
@inlinable public static
func ?= (pattern:MaskedVersion?, version:Self) -> Bool
{
pattern ?= .init(version)
}
@inlinable public
init(toolchain string:some StringProtocol) throws
{
self = try Rule<String.Index>.Toolchain.parse(string.unicodeScalars)
}
@inlinable public
init(parsing string:some StringProtocol) throws
{
self = try Rule<String.Index>.parse(string.unicodeScalars)
}
@available(*, deprecated)
@inlinable public
init?<S>(_ string:S) where S:StringProtocol
{
do
{
try self.init(parsing: string)
}
catch
{
return nil
}
}
}
extension MaskedVersion:LosslessStringConvertible
{
@inlinable public
var description:String
{
switch self
{
case .major(let major):
return "\(major)"
case .minor(let major, let minor):
return "\(major).\(minor)"
case .patch(let major, let minor, let patch):
return "\(major).\(minor).\(patch)"
case .edition(let major, let minor, let patch, let edition):
return "\(major).\(minor).\(patch).\(edition)"
case .nightly(year: let year, month: let month, day: let day):
return "\(year)-\(month)-\(day)"
case .hourly(year: let year, month: let month, day: let day, letter: let letter):
return "\(year)-\(month)-\(day)-\(Unicode.Scalar.init(letter))"
}
}
}