aboutsummaryrefslogtreecommitdiff
path: root/libbpkg
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2023-03-22 13:18:24 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2023-03-23 18:32:37 +0300
commit723a15c5390d0c5eb42f2082fcedb7262e7bc856 (patch)
tree7bef948322e2de710f44943e1e0dd621dc9b0d86 /libbpkg
parentc97dba3a4f2af33091112a347e181a5a2edc9914 (diff)
Add package_manifest::effective_type_sub_options()
Diffstat (limited to 'libbpkg')
-rw-r--r--libbpkg/manifest.cxx28
-rw-r--r--libbpkg/manifest.hxx18
-rw-r--r--libbpkg/manifest.ixx12
3 files changed, 42 insertions, 16 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx
index 8db4026..3f4b6af 100644
--- a/libbpkg/manifest.cxx
+++ b/libbpkg/manifest.cxx
@@ -3643,16 +3643,7 @@ namespace bpkg
if (m.type)
bad_name ("package type redefinition");
- // Strip the type extra information, if present.
- //
- size_t p (v.find (','));
- if (p != string::npos)
- {
- v.resize (p);
- trim_right (v);
- }
-
- if (v.empty ())
+ if (v.empty () || v.find (',') == 0)
bad_value ("empty package type");
m.type = move (v);
@@ -4489,6 +4480,23 @@ namespace bpkg
p, move (nv), function<translate_function> (), iu, cv, fl, *this);
}
+ strings package_manifest::
+ effective_type_sub_options (const optional<string>& t)
+ {
+ strings r;
+
+ if (t)
+ {
+ for (size_t b (0), e (0); next_word (*t, b, e, ','); )
+ {
+ if (b != 0)
+ r.push_back (trim (string (*t, b, e - b)));
+ }
+ }
+
+ return r;
+ }
+
optional<text_type> package_manifest::
effective_description_type (bool iu) const
{
diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx
index 1d45edf..c922cc4 100644
--- a/libbpkg/manifest.hxx
+++ b/libbpkg/manifest.hxx
@@ -1168,12 +1168,12 @@ namespace bpkg
butl::optional<std::string> sha256sum;
butl::optional<std::string> fragment;
- // Translate optional type to either `exe`, `lib`, or `other`.
+ // Extract the name from optional type, returning either `exe`, `lib`, or
+ // `other`.
//
- // Specifically, if type is present but is not one of the recognized
- // names, then return `other`. If type is absent and the package name
- // starts with the `lib` prefix, then return `lib`. Otherwise, return
- // `exe`.
+ // Specifically, if type is present but the name is not recognized, then
+ // return `other`. If type is absent and the package name starts with the
+ // `lib` prefix, then return `lib`. Otherwise, return `exe`.
//
std::string
effective_type () const;
@@ -1181,6 +1181,14 @@ namespace bpkg
static std::string
effective_type (const butl::optional<std::string>&, const package_name&);
+ // Extract sub-options from optional type.
+ //
+ strings
+ effective_type_sub_options () const;
+
+ static strings
+ effective_type_sub_options (const butl::optional<std::string>&);
+
// Translate the potentially empty list of languages to a non-empty one.
//
// Specifically, if the list of languages is not empty, then return it as
diff --git a/libbpkg/manifest.ixx b/libbpkg/manifest.ixx
index d6eb4a6..589d00f 100644
--- a/libbpkg/manifest.ixx
+++ b/libbpkg/manifest.ixx
@@ -242,7 +242,11 @@ namespace bpkg
effective_type (const butl::optional<std::string>& t, const package_name& n)
{
if (t)
- return *t == "exe" || *t == "lib" ? *t : "other";
+ {
+ std::string tp (*t, 0, t->find (','));
+ butl::trim (tp);
+ return tp == "exe" || tp == "lib" ? tp : "other";
+ }
const std::string& s (n.string ());
return s.size () > 3 && s.compare (0, 3, "lib") == 0 ? "lib" : "exe";
@@ -254,6 +258,12 @@ namespace bpkg
return effective_type (type, name);
}
+ inline strings package_manifest::
+ effective_type_sub_options () const
+ {
+ return effective_type_sub_options (type);
+ }
+
inline butl::small_vector<language, 1> package_manifest::
effective_languages (const butl::small_vector<language, 1>& ls,
const package_name& n)