@@ -14,45 +14,6 @@ import TSCUtility
1414
1515// TODO: maybe move this to TSC.
1616extension Version {
17- /// Create a version from a string, replacing unknown trailing components with '0'.
18- init ? ( potentiallyIncompleteVersionString string: String ) {
19- // This is a copied version of TSC's version parsing, modified to fill
20- // in missing components if needed.
21- let prereleaseStartIndex = string. firstIndex ( of: " - " )
22- let metadataStartIndex = string. firstIndex ( of: " + " )
23-
24- let requiredEndIndex = prereleaseStartIndex ?? metadataStartIndex ?? string. endIndex
25- let requiredCharacters = string. prefix ( upTo: requiredEndIndex)
26- var requiredComponents = requiredCharacters
27- . split ( separator: " . " , maxSplits: 2 , omittingEmptySubsequences: false )
28- . map ( String . init) . compactMap ( { Int ( $0) } ) . filter ( { $0 >= 0 } )
29-
30- requiredComponents. append ( contentsOf:
31- Array ( repeating: 0 ,
32- count: max ( 0 , 3 - requiredComponents. count) ) )
33-
34- let major = requiredComponents [ 0 ]
35- let minor = requiredComponents [ 1 ]
36- let patch = requiredComponents [ 2 ]
37-
38- func identifiers( start: String . Index ? , end: String . Index ) -> [ String ] {
39- guard let start = start else { return [ ] }
40- let identifiers = string [ string. index ( after: start) ..< end]
41- return identifiers. split ( separator: " . " ) . map ( String . init)
42- }
43-
44- let prereleaseIdentifiers = identifiers (
45- start: prereleaseStartIndex,
46- end: metadataStartIndex ?? string. endIndex)
47- let buildMetadataIdentifiers = identifiers (
48- start: metadataStartIndex,
49- end: string. endIndex)
50-
51- self . init ( major, minor, patch,
52- prereleaseIdentifiers: prereleaseIdentifiers,
53- buildMetadataIdentifiers: buildMetadataIdentifiers)
54- }
55-
5617 /// Returns the version with out any build/release metadata numbers.
5718 var withoutBuildNumbers : Version {
5819 return Version ( self . major, self . minor, self . patch)
0 commit comments