tryParseVersion

Parse s as a semantic version number.

Semantic versions are usually represented as string as: MAJOR[.MINOR[.PATCH]][-PRERELEASE][+BUILD].

For ease of use, a leading v or a leading = are also accepted.

@safe pure nothrow @nogc
tryParseVersion
(
scope const(char)[] s
)

Examples

assert(*tryParseVersion("0.0.0") == Version(0,0,0));
assert(*tryParseVersion("0.0.1") == Version(0,0,1));
assert(*tryParseVersion("0.1.1") == Version(0,1,1));
assert(*tryParseVersion("1.1.1") == Version(1,1,1));
assert(!tryParseVersion(""));
assert(!tryParseVersion("").isValid);
assert(!tryParseVersion("_").isValid);
assert(!tryParseVersion("").isValid);
assert(!tryParseVersion("1").isValid);
assert(!tryParseVersion("_").isValid);
assert(!tryParseVersion("1.").isValid);
assert(!tryParseVersion("1._").isValid);
assert(!tryParseVersion("1.1.").isValid);
assert(!tryParseVersion("1.1").isValid);
assert(!tryParseVersion("1.1_1").isValid);
assert(!tryParseVersion("1-1-1").isValid);
assert(!tryParseVersion("_._.__").isValid);
assert(!tryParseVersion("1._.__").isValid);
assert(!tryParseVersion("1.1.__").isValid);
assert(*tryParseVersion("v1.1.1") == Version(1,1,1));
assert(*tryParseVersion("=1.1.1") == Version(1,1,1));

See Also

Meta