Flox Package Database 1
CRUD Operations on Nix Package Metadata
|
Interfaces for analyzing version numbers. More...
Classes | |
class | VersionException |
Typed exception wrapper used for version parsing/comparison errors. More... | |
Functions | |
bool | isSemver (const std::string &version) |
bool | isDate (const std::string &version) |
bool | isCoercibleToSemver (const std::string &version) |
std::optional< std::string > | coerceSemver (std::string_view version) |
Attempt to coerce strings such as "v1.0.2" or 1.0 to valid semantic version strings. | |
bool | isSemverRange (const std::string &version) |
Determine if version is a valid semantic version range string. | |
std::pair< int, std::string > | runSemver (const std::list< std::string > &args) |
Invokes node-semver by exec . | |
static std::string | cleanRange (const std::string &range) |
Strip any '*', 'x', or 'X' characters from the range. | |
std::list< std::string > | semverSat (const std::string &range, const std::list< std::string > &versions) |
Filter a list of versions by a node-semver semantic version range. | |
Variables | |
static const char *const | semverREStr = "(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[-[:alnum:]_+.]+)?" |
static const char *const | semverLooseREStr |
static const char *const | semverCoerceREStr |
static const char *const | dateREStr |
Interfaces for analyzing version numbers.
Interfaces for analyzing version numbers
std::optional< std::string > versions::coerceSemver | ( | std::string_view | version | ) |
Attempt to coerce strings such as "v1.0.2"
or 1.0
to valid semantic version strings.
std::nullopt
iff version cannot be interpreted as semantic version. A valid semantic version string otherwise. Capture Groups Example:
bool versions::isCoercibleToSemver | ( | const std::string & | version | ) |
true
iff version can be interpreted as semantic version. bool versions::isDate | ( | const std::string & | version | ) |
true
iff version is a datestamp-like version string. bool versions::isSemver | ( | const std::string & | version | ) |
true
iff version is a valid semantic version string. bool versions::isSemverRange | ( | const std::string & | version | ) |
Determine if version is a valid semantic version range string.
This is far from a complete check, but it should be sufficient for our usage. This essentially checks that the first token of the string is a valid range, a 4.2.0 - 5.3.1
style range, or a special token. ( See expanded discussion below for futher details ).
Leading and trailing space is ignored.
This will count exact version matches such as 4.2.0
as ranges.
This will count the empty string ( ""
), *
, any
, and latest
as ranges ( aligning with node-semver
).
Limitations: This covers the 99% case to distinguish between a range and "static" version. The main reason to detect this is because from the CLI we can't immediately tell whether <NAME>@<VERSION-OR-SEMVER>
is an exact version match ( like a date ), or a real range. This does a "best effort" detection which is suitable for our purposes today.
true
iff version is a valid semantic version range string.std::pair< int, std::string > versions::runSemver | ( | const std::list< std::string > & | args | ) |
Invokes node-semver
by exec
.
args | List of arguments to pass to semver executable. |
std::list< std::string > versions::semverSat | ( | const std::string & | range, |
const std::list< std::string > & | versions | ||
) |
Filter a list of versions by a node-semver
semantic version range.
range | A semantic version range as taken by node-semver . |
versions | A list of semantic versions to filter. |
|
static |
Match '-' separated date strings, e.g. ‘2023-05-31’ or ‘5-1-23’.
|
static |
Coercively matches Semantic Version Strings, e.g. ‘v1.0-pre’.
|
static |
Matches loose versions which may omit trailing 0s.
|
static |
Matches Semantic Version strings, e.g. ‘4.2.0-pre’.