Axle v0.14.1
Package

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 raise
ParseException 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-level
const is unsupported).

Free functions

TypeMethod and description
bool
__isAlnumDash(byte : i32) : bool true for an ASCII alphanumeric byte or '-' — the character set
SemVer allows in prerelease / build identifiers.
bool
__rangeAllDigits(s : string, start : i64, end : i64) : bool true when every byte of the non-empty range [start, end) is a
digit. An empty range is vacuously true.
i64
__headEnd(s : string, srcLen : i64) : i64 End of the version "head" (the major.minor.patch[-pre] part): the
first '+', or the full length when there is no build metadata.
i64
__numericEnd(s : string, srcLen : i64) : i64 End of the numeric major.minor.patch core: the first '-' within
the head, or the head end when there is no prerelease.
i64
__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.
bool
__validateIds(s : string, start : i64, end : i64, isPrerelease : bool) : bool 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).
bool
__semverValid(s : string, srcLen : i64) : bool Full SemVer 2.0.0 well-formedness check (the foundation every public
function builds on).
i64
__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.
string
__substr(s : string, start : i64, end : i64) : string Materialise the bytes of [start, end) as an owned string ("" for
an empty range).
i32
__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.
i32
__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.
i32
versionMajor(v : string) : i32 Major component. Raises ParseException on malformed input.
i32
versionMinor(v : string) : i32 Minor component. Raises ParseException on malformed input.
i32
versionPatch(v : string) : i32 Patch component. Raises ParseException on malformed input.
string
versionPrerelease(v : string) : string Prerelease identifier string (without the leading '-'), or "" when
absent. Raises ParseException on malformed input.
string
versionBuild(v : string) : string Build-metadata string (without the leading '+'), or "" when
absent. Raises ParseException on malformed input.
bool
versionIsValid(v : string) : bool true when v is a well-formed SemVer 2.0.0 string.
i32
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 is
malformed.

Method detail

#__isAlnumDash

__isAlnumDash(byte : i32) : bool

true for an ASCII alphanumeric byte or '-' — the character set
SemVer allows in prerelease / build identifiers.

Parameters
byte ASCII byte value to classify

#__rangeAllDigits

__rangeAllDigits(s : string, start : i64, end : i64) : bool

true when every byte of the non-empty range [start, end) is a
digit. An empty range is vacuously true.

Parameters
s version string holding the range
start inclusive byte offset where the range begins
end exclusive byte offset where the range ends

#__headEnd

__headEnd(s : string, srcLen : i64) : i64

End of the version "head" (the major.minor.patch[-pre] part): the
first '+', or the full length when there is no build metadata.

Parameters
s version string to scan
srcLen byte length of s

#__numericEnd

__numericEnd(s : string, srcLen : i64) : i64

End of the numeric major.minor.patch core: the first '-' within
the head, or the head end when there is no prerelease.

Parameters
s version string to scan
srcLen byte length of s

#__parseNumericId

__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.

Parameters
s version string holding the identifier
start inclusive byte offset where the identifier begins
end exclusive byte offset where the identifier ends

#__validateIds

__validateIds(s : string, start : i64, end : i64, isPrerelease : bool) : bool

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).

Parameters
s version string holding the identifier list
start inclusive byte offset where the list begins
end exclusive byte offset where the list ends
isPrerelease true to apply the prerelease no-leading-zero rule

#__semverValid

__semverValid(s : string, srcLen : i64) : bool

Full SemVer 2.0.0 well-formedness check (the foundation every public
function builds on).

Parameters
s candidate SemVer string to validate
srcLen byte length of s

#__numComponent

__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.

Parameters
s validated version string
srcLen byte length of s
which component selector (0 major, 1 minor, 2 patch)

#__substr

__substr(s : string, start : i64, end : i64) : string

Materialise the bytes of [start, end) as an owned string ("" for
an empty range).

Parameters
s source version string
start inclusive byte offset where the slice begins
end exclusive byte offset where the slice ends

#__cmpPreId

__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.

Parameters
a version string holding the left identifier
aStart inclusive start offset of the left identifier
aEnd exclusive end offset of the left identifier
b version string holding the right identifier
bStart inclusive start offset of the right identifier
bEnd exclusive end offset of the right identifier

#__cmpPreRanges

__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.

Parameters
a version string holding the left prerelease range
aStart inclusive start offset of the left range
aEnd exclusive end offset of the left range
b version string holding the right prerelease range
bStart inclusive start offset of the right range
bEnd exclusive end offset of the right range

#versionMajor

versionMajor(v : string) : i32 ! ParseException

Major component. Raises ParseException on malformed input.

Parameters
v SemVer string to extract the major number from

#versionMinor

versionMinor(v : string) : i32 ! ParseException

Minor component. Raises ParseException on malformed input.

Parameters
v SemVer string to extract the minor number from

#versionPatch

versionPatch(v : string) : i32 ! ParseException

Patch component. Raises ParseException on malformed input.

Parameters
v SemVer string to extract the patch number from

#versionPrerelease

versionPrerelease(v : string) : string ! ParseException

Prerelease identifier string (without the leading '-'), or "" when
absent. Raises ParseException on malformed input.

Parameters
v SemVer string to extract the prerelease tag from

#versionBuild

versionBuild(v : string) : string ! ParseException

Build-metadata string (without the leading '+'), or "" when
absent. Raises ParseException on malformed input.

Parameters
v SemVer string to extract the build metadata from

#versionIsValid

versionIsValid(v : string) : bool

true when v is a well-formed SemVer 2.0.0 string.

Parameters
v candidate string to test for SemVer well-formedness

#versionCompare

versionCompare(a : string, b : string) : i32 ! ParseException

Compare two versions, returning -1 / 0 / 1 (a < b / a == b / a > b).
Build metadata is ignored. Raises ParseException if either side is
malformed.

Parameters
a left-hand SemVer version to compare
b right-hand SemVer version to compare