aboutsummaryrefslogtreecommitdiff
path: root/libbpkg/manifest.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2021-08-04 20:31:30 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-08-05 12:18:08 +0300
commit0592d58e5366eac92bc99ef9bdb4368e07c0ddf9 (patch)
treeb0eac4fbf15f8c502321a3ad9c1ac670c070b1f3 /libbpkg/manifest.cxx
parentda2d334f608c9fb9bf88f90cc50cd564441581f7 (diff)
Add extract_package_name() and extract_package_version()
Diffstat (limited to 'libbpkg/manifest.cxx')
-rw-r--r--libbpkg/manifest.cxx37
1 files changed, 37 insertions, 0 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx
index 210aa3b..d4c3f9d 100644
--- a/libbpkg/manifest.cxx
+++ b/libbpkg/manifest.cxx
@@ -4573,4 +4573,41 @@ namespace bpkg
s.next ("", ""); // End of manifest.
}
+
+ // extract_package_*()
+ //
+ package_name
+ extract_package_name (const char* s, bool allow_version)
+ {
+ if (!allow_version)
+ return package_name (s);
+
+ // Calculate the package name length as a length of the prefix that
+ // doesn't contain spaces, slashes and the version constraint starting
+ // characters. Note that none of them are valid package name characters.
+ //
+ size_t n (strcspn (s, " /=<>([~^"));
+ return package_name (string (s, n));
+ }
+
+ version
+ extract_package_version (const char* s, bool fold_zero_revision)
+ {
+ using traits = string::traits_type;
+
+ if (const char* p = traits::find (s, traits::length (s), '/'))
+ {
+ version r (p + 1, fold_zero_revision);
+
+ if (r.release && r.release->empty ())
+ throw invalid_argument ("earliest version");
+
+ if (r.compare (stub_version, true /* ignore_revision */) == 0)
+ throw invalid_argument ("stub version");
+
+ return r;
+ }
+
+ return version ();
+ }
}