From 33f5e4665f961de406802f13420c66598c7b32e1 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 17 Jan 2023 13:10:40 +0300 Subject: Add distribution_name_value::distribution() --- libbpkg/manifest.cxx | 19 +++++++++++++++++++ libbpkg/manifest.hxx | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx index 82a11f3..637d0ae 100644 --- a/libbpkg/manifest.cxx +++ b/libbpkg/manifest.cxx @@ -3240,6 +3240,25 @@ namespace bpkg return r; } + // distribution_name_value + // + optional distribution_name_value:: + distribution (const string& s) const + { + size_t sn (s.size ()); + size_t nn (name.size ()); + + if (nn > sn && name.compare (nn - sn, sn, s) == 0) + { + size_t p (name.find ('-')); + + if (p == nn - sn) + return string (name, 0, p); + } + + return nullopt; + } + // pkg_package_manifest // static build_class_expr diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx index 757fc92..055cb7e 100644 --- a/libbpkg/manifest.hxx +++ b/libbpkg/manifest.hxx @@ -1156,6 +1156,12 @@ namespace bpkg distribution_name_value (std::string n, std::string v) : name (std::move (n)), value (std::move (v)) {} + + // Return the name's component if the name has the + // specified suffix, which is assumed to be valid (-name, etc). + // + butl::optional + distribution (const std::string& suffix) const; }; class LIBBPKG_EXPORT package_manifest -- cgit v1.1