std/text/version
std/version — Semantic Versioning 2.0.0 parser + comparator, in
pure Axle.
Strict: input must match <major>.<minor>.<patch> with optional-prerelease and +build suffixes. Any deviation makes the value
invalid; the component extractors and the comparator raiseParseException rather than treat malformed input as valid.
The parser never materialises substrings while validating — it
walks the input by byte offset and validates each region in place.
Comparison ignores +build (per spec) and follows the pre-release
ordering rules: numeric identifiers compare numerically (by digit
count then lexicographically, equivalent for canonical no-leading-
zero ids), alphanumeric compare lexicographically, and a numeric
identifier sorts below an alphanumeric one; a prerelease sorts
before the corresponding release.
The structural ASCII bytes are named in each function (module-levelconst is unsupported).
Free functions
| Type | Method and description |
|---|---|
| __isAlnumDash(byte : i32) : bool true for an ASCII alphanumeric byte or '-' — the character setSemVer allows in prerelease / build identifiers. |
| __rangeAllDigits(s : string, start : i64, end : i64) : bool true when every byte of the non-empty range [start, end) is adigit. An empty range is vacuously true. |
| __headEnd(s : string, srcLen : i64) : i64 End of the version "head" (the major.minor.patch[-pre] part): thefirst '+', or the full length when there is no build metadata. |
| __numericEnd(s : string, srcLen : i64) : i64 End of the numeric major.minor.patch core: the first '-' withinthe head, or the head end when there is no prerelease. |
| __parseNumericId(s : string, start : i64, end : i64) : i64 Parse the dotless numeric identifier in [start, end) to its value,or -1 when it is empty, has a forbidden leading zero, holds a non-digit, or overflows the SemVer u32 range. |
| __validateIds(s : string, start : i64, end : i64, isPrerelease : bool) : bool Validate a '.'-separated identifier list in [start, end). Eachidentifier must be non-empty and contain only alphanumerics / '-'.When isPrerelease is set, a purely-numeric identifier may not carrya leading zero (matching the prerelease rule; build metadata is exempt). |
| __semverValid(s : string, srcLen : i64) : bool Full SemVer 2.0.0 well-formedness check (the foundation every public function builds on). |
| __numComponent(s : string, srcLen : i64, which : i32) : i64 The which-th numeric component (0 = major, 1 = minor, 2 = patch),assuming s has already been validated. |
| __substr(s : string, start : i64, end : i64) : string Materialise the bytes of [start, end) as an owned string ("" foran empty range). |
| __cmpPreId(a : string, aStart : i64, aEnd : i64, b : string, bStart : i64, bEnd : i64) : i32 Compare two prerelease identifiers per SemVer: numeric < numeric by value, numeric < alphanumeric, alphanumeric compared lexically. |
| __cmpPreRanges(
a : string,
aStart : i64,
aEnd : i64,
b : string,
bStart : i64,
bEnd : i64
) : i32 Compare two non-empty prerelease ranges identifier by identifier. A longer identifier list wins once all shared identifiers tie. |
| versionMajor(v : string) : i32 Major component. Raises ParseException on malformed input. |
| versionMinor(v : string) : i32 Minor component. Raises ParseException on malformed input. |
| versionPatch(v : string) : i32 Patch component. Raises ParseException on malformed input. |
| versionPrerelease(v : string) : string Prerelease identifier string (without the leading '-'), or "" whenabsent. Raises ParseException on malformed input. |
| versionBuild(v : string) : string Build-metadata string (without the leading '+'), or "" whenabsent. Raises ParseException on malformed input. |
| versionIsValid(v : string) : bool true when v is a well-formed SemVer 2.0.0 string. |
| versionCompare(a : string, b : string) : i32 Compare two versions, returning -1 / 0 / 1 (a < b / a == b / a > b). Build metadata is ignored. Raises ParseException if either side ismalformed. |
Method detail
#__isAlnumDash
true for an ASCII alphanumeric byte or '-' — the character set
SemVer allows in prerelease / build identifiers.
byte ASCII byte value to classify#__rangeAllDigits
true when every byte of the non-empty range [start, end) is a
digit. An empty range is vacuously true.
s version string holding the rangestart inclusive byte offset where the range beginsend exclusive byte offset where the range ends#__headEnd
End of the version "head" (the major.minor.patch[-pre] part): the
first '+', or the full length when there is no build metadata.
s version string to scansrcLen byte length of s#__numericEnd
End of the numeric major.minor.patch core: the first '-' within
the head, or the head end when there is no prerelease.
s version string to scansrcLen byte length of s#__parseNumericId
Parse the dotless numeric identifier in [start, end) to its value,
or -1 when it is empty, has a forbidden leading zero, holds a
non-digit, or overflows the SemVer u32 range.
s version string holding the identifierstart inclusive byte offset where the identifier beginsend exclusive byte offset where the identifier ends#__validateIds
Validate a '.'-separated identifier list in [start, end). Each
identifier must be non-empty and contain only alphanumerics / '-'.
When isPrerelease is set, a purely-numeric identifier may not carry
a leading zero (matching the prerelease rule; build metadata is
exempt).
s version string holding the identifier liststart inclusive byte offset where the list beginsend exclusive byte offset where the list endsisPrerelease true to apply the prerelease no-leading-zero rule#__semverValid
Full SemVer 2.0.0 well-formedness check (the foundation every public
function builds on).
s candidate SemVer string to validatesrcLen byte length of s#__numComponent
The which-th numeric component (0 = major, 1 = minor, 2 = patch),
assuming s has already been validated.
s validated version stringsrcLen byte length of swhich component selector (0 major, 1 minor, 2 patch)#__substr
Materialise the bytes of [start, end) as an owned string ("" for
an empty range).
s source version stringstart inclusive byte offset where the slice beginsend exclusive byte offset where the slice ends#__cmpPreId
Compare two prerelease identifiers per SemVer: numeric < numeric by
value, numeric < alphanumeric, alphanumeric compared lexically.
a version string holding the left identifieraStart inclusive start offset of the left identifieraEnd exclusive end offset of the left identifierb version string holding the right identifierbStart inclusive start offset of the right identifierbEnd exclusive end offset of the right identifier#__cmpPreRanges
Compare two non-empty prerelease ranges identifier by identifier.
A longer identifier list wins once all shared identifiers tie.
a version string holding the left prerelease rangeaStart inclusive start offset of the left rangeaEnd exclusive end offset of the left rangeb version string holding the right prerelease rangebStart inclusive start offset of the right rangebEnd exclusive end offset of the right range#versionMajor
Major component. Raises ParseException on malformed input.
v SemVer string to extract the major number from#versionMinor
Minor component. Raises ParseException on malformed input.
v SemVer string to extract the minor number from#versionPatch
Patch component. Raises ParseException on malformed input.
v SemVer string to extract the patch number from#versionPrerelease
Prerelease identifier string (without the leading '-'), or "" when
absent. Raises ParseException on malformed input.
v SemVer string to extract the prerelease tag from#versionBuild
Build-metadata string (without the leading '+'), or "" when
absent. Raises ParseException on malformed input.
v SemVer string to extract the build metadata from#versionIsValid
true when v is a well-formed SemVer 2.0.0 string.
v candidate string to test for SemVer well-formedness#versionCompare
Compare two versions, returning -1 / 0 / 1 (a < b / a == b / a > b).
Build metadata is ignored. Raises ParseException if either side is
malformed.
a left-hand SemVer version to compareb right-hand SemVer version to compare