From 8561af5a2551ec453c9888125de273f2cc2940c0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 14 Aug 2018 14:09:32 +0200 Subject: Add support for parsing semantic and semantic-like versions --- libbutl/standard-version.cxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'libbutl/standard-version.cxx') 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 (v); return true; } -- cgit v1.1