28.5 Comparing semantic version specifications

Function: mbfl_semver_compare_var _RV STRING_REP1 STRING_REP2

Store in the data variable whose name is _RV the result of comparing the semantic version specifications STRING_REP1 and STRING_REP2; when successful return 0, otherwise return 1.

The value stored in the result variable is the classic ternary comparison result:

-1

if STRING_REP1 < STRING_REP2.

0

If STRING_REP1 = STRING_REP2.

+1

If STRING_REP1 > STRING_REP2.

Usage examples:

{
  mbfl_declare_varref(RV)
  mbfl_semver_compare_var mbfl_datavar(RV) '1.2.3' '1.2.3'
  $?            ⇒ 0
  $RV           ⇒ 0
}

{
  mbfl_declare_varref(RV)
  mbfl_semver_compare_var mbfl_datavar(RV) '1.2.3' '1.9.3'
  $?            ⇒  0
  $RV           ⇒ -1
}

{
  mbfl_declare_varref(RV)
  mbfl_semver_compare_var mbfl_datavar(RV) '1.2.3-alpha.1' '1.2.3-alpha.0'
  $?            ⇒  0
  $RV           ⇒ +1
}
Function: mbfl_semver_compare_components_var _RV SEMVER_SPEC1 SEMVER_SPEC2

Like mbfl_semver_compare_var() but compare already parsed semantic version specifications. Examples:

mbfl_default_object_declare(PARSER)

mbfl_default_object_declare(SPEC1)
mbfl_default_object_declare(INPUT1)

mbfl_default_object_declare(SPEC2)
mbfl_default_object_declare(INPUT2)

mbfl_semver_parser_make_default _(PARSER)

mbfl_semver_parser_input_make _(INPUT1) '1.2.3-alpha.3+x86-64' 0
mbfl_semver_parser_input_make _(INPUT2) '1.2.9-devel.2+x86-64' 0

mbfl_semver_parse _(SPEC1) _(PARSER) _(INPUT1)
mbfl_semver_parse _(SPEC2) _(PARSER) _(INPUT2)

mbfl_declare_varref(RV)

mbfl_semver_compare_components_var _(RV) _(SPEC1) _(SPEC2)

$?      ⇒  0
$RV     ⇒ -1

This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.