diff options
-rw-r--r-- | libbutl/standard-version.cxx | 25 | ||||
-rw-r--r-- | libbutl/standard-version.mxx | 4 | ||||
-rw-r--r-- | tests/standard-version/testscript | 12 |
3 files changed, 21 insertions, 20 deletions
diff --git a/libbutl/standard-version.cxx b/libbutl/standard-version.cxx index d8582dd..b7678ac 100644 --- a/libbutl/standard-version.cxx +++ b/libbutl/standard-version.cxx @@ -137,25 +137,21 @@ namespace butl { auto bail = [] (const char* m) {throw invalid_argument (m);}; - // Pre-parse the first component to see if the version starts with epoch, - // to keep the subsequent parsing straightforward. - // - bool ep (false); - { - char* e (nullptr); - strtoull (s.c_str (), &e, 10); - ep = *e == '~'; - } - // Note that here and below p is less or equal n, and so s[p] is always // valid. // size_t p (0), n (s.size ()); + bool ep (s[p] == '+'); // Has epoch. + if (ep) { - epoch = parse_uint16 (s, p, "invalid epoch", 1, uint16_t (~0)); - ++p; // Skip '~'. + epoch = parse_uint16 (s, ++p, "invalid epoch", 1, uint16_t (~0)); + + // Skip the terminating character if it is '-', otherwise fail. + // + if (s[p++] != '-') + bail ("'-' expected after epoch"); } uint16_t ma, mi, bf, ab (0); @@ -446,8 +442,9 @@ namespace butl if (epoch != 0) { - r = to_string (epoch); - r += '~'; + r += '+'; + r += to_string (epoch); + r += '-'; } r += string_project (); diff --git a/libbutl/standard-version.mxx b/libbutl/standard-version.mxx index e6c6f27..b161063 100644 --- a/libbutl/standard-version.mxx +++ b/libbutl/standard-version.mxx @@ -44,8 +44,8 @@ LIBBUTL_MODEXPORT namespace butl { // The build2 "standard version" (specific, earliest and stub): // - // [<epoch>~]<maj>.<min>.<patch>[-(a|b).<num>[.<snapsn>[.<snapid>]]][+<rev>] - // [<epoch>~]<maj>.<min>.<patch>- + // [+<epoch>-]<maj>.<min>.<patch>[-(a|b).<num>[.<snapsn>[.<snapid>]]][+<rev>] + // [+<epoch>-]<maj>.<min>.<patch>- // 0[+<revision>] // struct LIBBUTL_SYMEXPORT standard_version diff --git a/tests/standard-version/testscript b/tests/standard-version/testscript index ebc24d5..f06b178 100644 --- a/tests/standard-version/testscript +++ b/tests/standard-version/testscript @@ -51,7 +51,7 @@ : epoch : $* <<EOF >>EOF - 4~1.2.3 + +4-1.2.3 EOF : stub @@ -71,6 +71,10 @@ : invalid : { + : epoch + : + $* <'+1+' 2>"'-' expected after epoch" == 1 + : major : $* <'a' 2>'invalid major version' == 1 @@ -93,7 +97,7 @@ : zero-version : - $* <'1~0.0.0' 2>'0.0.0 version' == 1 + $* <'+1-0.0.0' 2>'0.0.0 version' == 1 : a-b-expected : @@ -190,8 +194,8 @@ : epoch : { - $* '4~1.2.3' '4~1.2.3' >'0' : equal - $* '1.2.4' '4~1.2.3' >'-1': less + $* '+4-1.2.3' '+4-1.2.3' >'0' : equal + $* '1.2.4' '+4-1.2.3' >'-1': less } : non-prerelease |