compareVersions

Compares the precedence of two SemVer version strings.

The version strings must be validated using isValidVersion before being passed to this function. Note that the build meta data suffix (if any) is being ignored when comparing version numbers.

@safe
int
compareVersions
pure @nogc
(
string a
,
string b
)

Return Value

Type: int

Returns a negative number if a is a lower version than b, 0 if they are equal, and a positive number otherwise.

Examples

1 assert(compareVersions("1.0.0", "1.0.0") == 0);
2 assert(compareVersions("1.0.0+b1", "1.0.0+b2") == 0);
3 assert(compareVersions("1.0.0", "2.0.0") < 0);
4 assert(compareVersions("1.0.0-beta", "1.0.0") < 0);
5 assert(compareVersions("1.0.1", "1.0.0") > 0);

Meta