aboutsummaryrefslogtreecommitdiff
path: root/libbutl/standard-version.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-08-14 14:09:32 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-08-14 14:09:32 +0200
commit8561af5a2551ec453c9888125de273f2cc2940c0 (patch)
tree4458e955d33f9aaf7e904c8de717803a33ecc81f /libbutl/standard-version.cxx
parent7c665d965c0ebb259849d5032faa0854c6ae94f2 (diff)
Add support for parsing semantic and semantic-like versions
Diffstat (limited to 'libbutl/standard-version.cxx')
-rw-r--r--libbutl/standard-version.cxx13
1 files changed, 9 insertions, 4 deletions
diff --git a/libbutl/standard-version.cxx b/libbutl/standard-version.cxx
index e4180d1..fc2d528 100644
--- a/libbutl/standard-version.cxx
+++ b/libbutl/standard-version.cxx
@@ -42,12 +42,17 @@ using namespace std;
namespace butl
{
- // Utility functions
+ // Parse uint64_t from the specified string starting at the specified
+ // position and check the min/max constraints. If successful, save the
+ // result, update the position to point to the next character, and return
+ // true. Otherwise return false (result and position are unchanged).
//
- static bool
+ // Note: also used for semantic_version parsing.
+ //
+ bool
parse_uint64 (const string& s, size_t& p,
uint64_t& r,
- uint64_t min, uint64_t max)
+ uint64_t min = 0, uint64_t max = uint64_t (~0))
{
if (s[p] == '-' || s[p] == '+') // strtoull() allows these.
return false;
@@ -59,8 +64,8 @@ namespace butl
if (errno == ERANGE || b == e || v < min || v > max)
return false;
+ r = v;
p = e - s.c_str ();
- r = static_cast<uint64_t> (v);
return true;
}