From 749cd532f72108b26a78cd2f0012e6abd72b3ce8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 28 Sep 2015 08:38:40 +0200 Subject: Factory common code for version, repository location parsing --- bpkg/manifest-utility.cxx | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 bpkg/manifest-utility.cxx (limited to 'bpkg/manifest-utility.cxx') diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx new file mode 100644 index 0000000..76c1957 --- /dev/null +++ b/bpkg/manifest-utility.cxx @@ -0,0 +1,44 @@ +// file : bpkg/manifest-utility.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include // invalid_argument + +#include + +using namespace std; + +namespace bpkg +{ + version + parse_version (const char* s) + try + { + return version (s); + } + catch (const invalid_argument& e) + { + error << "invalid package version '" << s << "': " << e.what (); + throw failed (); + } + + repository_location + parse_location (const char* s) + try + { + repository_location rl (s, repository_location ()); + + if (rl.relative ()) // Throws if the location is empty. + rl = repository_location ( + dir_path (s).complete ().normalize ().string ()); + + return rl; + } + catch (const invalid_argument& e) + { + error << "invalid repository location '" << s << "': " << e.what (); + throw failed (); + } +} -- cgit v1.1