Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
Classes | Functions | Variables
versions Namespace Reference

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
 

Detailed Description

Interfaces for analyzing version numbers.

Interfaces for analyzing version numbers

Function Documentation

◆ coerceSemver()

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.

Returns
std::nullopt iff version cannot be interpreted as semantic version. A valid semantic version string otherwise.

Capture Groups Example:

◆ isCoercibleToSemver()

bool versions::isCoercibleToSemver ( const std::string &  version)
Returns
true iff version can be interpreted as semantic version.

◆ isDate()

bool versions::isDate ( const std::string &  version)
Returns
true iff version is a datestamp-like version string.

◆ isSemver()

bool versions::isSemver ( const std::string &  version)
Returns
true iff version is a valid semantic version string.

◆ isSemverRange()

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.

Returns
true iff version is a valid semantic version range string.
See also
flox::resolver::ManifestDescriptor::semver

◆ runSemver()

std::pair< int, std::string > versions::runSemver ( const std::list< std::string > &  args)

Invokes node-semver by exec.

Parameters
argsList of arguments to pass to semver executable.
Returns
Pair of error-code and output string.

◆ semverSat()

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.

Parameters
rangeA semantic version range as taken by node-semver.
versionsA list of semantic versions to filter.
Returns
The list of semantic versions from versions which fall in the range specified by range.

Variable Documentation

◆ dateREStr

const char* const versions::dateREStr
static
Initial value:
= "([12][0-9][0-9][0-9]-[0-1]?[0-9]-[0-3]?[0-9]|"
"[0-1]?[0-9]-[0-3]?[0-9]-[12][0-9][0-9][0-9])"
"(-[-[:alnum:]_+.]+)?"

Match '-' separated date strings, e.g. ‘2023-05-31’ or ‘5-1-23’.

◆ semverCoerceREStr

const char* const versions::semverCoerceREStr
static
Initial value:
= "(.*@)?[vV]?(0*([0-9]+)(\\.0*([0-9]+)(\\.0*([0-9]+))?)?(-[-[:alnum:]_+.]+)?"
")"

Coercively matches Semantic Version Strings, e.g. ‘v1.0-pre’.

◆ semverLooseREStr

const char* const versions::semverLooseREStr
static
Initial value:
= "(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))?)?"
"(-[-[:alnum:]_+.]+)?"

Matches loose versions which may omit trailing 0s.

◆ semverREStr

const char* const versions::semverREStr = "(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-[-[:alnum:]_+.]+)?"
static

Matches Semantic Version strings, e.g. ‘4.2.0-pre’.