You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement lenient version parsing that doesn't require patch version
Added the `usesLenientParsing` parameter to `Version.init(versionString:) throws` and logic changes to enable parsing version strings without patch versions.
Added the `usesLenientParsing: Bool` associated type to `VersionError.invalidVersionCoreIdentifiersCount`, so the error message can be specialised for both strict and lenient parsing.
return"\(identifiers.count >3?"more than 3":"fewer than \(usesLenientParsing ?2:3)") identifiers in version core '\(identifiers.joined(separator:"."))'"
return"empty identifiers in version core '\(identifiers.joined(separator:"."))'"
@@ -85,15 +92,17 @@ public enum VersionError: Error, CustomStringConvertible {
85
92
}
86
93
87
94
extensionVersion{
88
-
// TODO: Rename this function to `init(string: String) throws`, after `init?(string: String)` is removed.
95
+
// TODO: Rename this function to `init(string:usesLenientParsing:) throws`, after `init?(string: String)` is removed.
89
96
// TODO: Find a better error-checking order.
90
97
// Currently, if a version string is "forty-two", this initializer throws an error that says "forty" is only 1 version core identifier, which is not enough.
91
98
// But this is misleading the user to consider "forty" as a valid version core identifier.
92
99
// We should find a way to check for (or throw) "wrong characters used" errors first, but without overly-complicating the logic.
93
100
/// Creates a version from the given string.
94
-
/// - Parameter versionString: The string to create the version from.
101
+
/// - Parameters:
102
+
/// - versionString: The string to create the version from.
103
+
/// - usesLenientParsing: A Boolean value indicating whether or not the version string should be parsed leniently. If `true`, then the patch version is assumed to be `0` if it's not provided in the version string; otherwise, the parsing strictly follows the Semantic Versioning 2.0.0 rules. This value defaults to `false`.
95
104
/// - Throws: A `VersionError` instance if the `versionString` doesn't follow [SemVer 2.0.0](https://semver.org).
// SemVer 2.0.0 allows only ASCII alphanumerical characters and "-" in the version string, except for "." and "+" as delimiters. ("-" is used as a delimiter between the version core and pre-release identifiers, but it's allowed within pre-release and metadata identifiers as well.)
98
107
// Alphanumerics check will come later, after each identifier is split out (i.e. after the delimiters are removed).
0 commit comments