aboutsummaryrefslogtreecommitdiff
path: root/bpkg/manifest-utility.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bpkg/manifest-utility.cxx')
-rw-r--r--bpkg/manifest-utility.cxx39
1 files changed, 39 insertions, 0 deletions
diff --git a/bpkg/manifest-utility.cxx b/bpkg/manifest-utility.cxx
index 76c1957..e44936f 100644
--- a/bpkg/manifest-utility.cxx
+++ b/bpkg/manifest-utility.cxx
@@ -12,6 +12,45 @@ using namespace std;
namespace bpkg
{
+ string
+ parse_package_name (const char* s)
+ {
+ using traits = string::traits_type;
+
+ size_t n (traits::length (s));
+
+ if (const char* p = traits::find (s, n, '/'))
+ n = static_cast<size_t> (p - s);
+
+ if (n == 0)
+ fail << "empty package name in '" << s << "'";
+
+ return string (s, n);
+ }
+
+ version
+ parse_package_version (const char* s)
+ {
+ using traits = string::traits_type;
+
+ if (const char* p = traits::find (s, traits::length (s), '/'))
+ {
+ if (*++p == '\0')
+ fail << "empty package version in '" << s << "'";
+
+ try
+ {
+ return version (p);
+ }
+ catch (const invalid_argument& e)
+ {
+ fail << "invalid package version '" << p << "': " << e.what ();
+ }
+ }
+
+ return version ();
+ }
+
version
parse_version (const char* s)
try