From a41a4869e74e5f7fc4ed9797661b1d450b1ce97a Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 3 Jun 2019 20:04:29 +0300 Subject: Add support for topics and keywords package manifest values --- libbpkg/manifest.cxx | 84 ++++++++++++++++++++++++++++++++++++++++++---------- libbpkg/manifest.hxx | 3 +- 2 files changed, 70 insertions(+), 17 deletions(-) (limited to 'libbpkg') diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx index 7e6e6d7..e27af54 100644 --- a/libbpkg/manifest.cxx +++ b/libbpkg/manifest.cxx @@ -1660,6 +1660,45 @@ namespace bpkg return r; }; + // Parse a string list (topics, keywords, etc). If the list length exceeds + // five entries, then truncate it if the truncate flag is set and throw + // manifest_parsing otherwise. + // + auto parse_list = [&bad_name, &bad_value] (const string& v, + strings& r, + char delim, + bool single_word, + bool truncate, + const char* what) + { + if (!r.empty ()) + bad_name (string ("package ") + what + " redefinition"); + + // Note that we parse the whole list to validate the entries. + // + list_parser lp (v.begin (), v.end (), delim); + for (string lv (lp.next ()); !lv.empty (); lv = lp.next ()) + { + if (single_word && lv.find_first_of (spaces) != string::npos) + bad_value (string ("only single-word ") + what + " allowed"); + + r.push_back (move (lv)); + } + + if (r.empty ()) + bad_value (string ("empty package ") + what + " specification"); + + // If the list length limit is exceeded then truncate it or throw. + // + if (r.size () > 5) + { + if (truncate) + r.resize (5); + else + bad_value (string ("up to five ") + what + " allowed"); + } + }; + auto flag = [fl] (package_manifest_flags f) { return (fl & f) != package_manifest_flags::none; @@ -1773,22 +1812,32 @@ namespace bpkg m.summary = move (v); } + else if (n == "topics") + { + parse_list (v, + m.topics, + ',' /* delim */, + false /* single_word */, + false /* truncate */, + "topics"); + } + else if (n == "keywords") + { + parse_list (v, + m.keywords, + ' ' /* delim */, + true /* single_word */, + false /* truncate */, + "keywords"); + } else if (n == "tags") { - if (!m.tags.empty ()) - bad_name ("package tags redefinition"); - - list_parser lp (v.begin (), v.end ()); - for (string lv (lp.next ()); !lv.empty (); lv = lp.next ()) - { - if (lv.find_first_of (spaces) != string::npos) - bad_value ("only single-word tags allowed"); - - m.tags.push_back (move (lv)); - } - - if (m.tags.empty ()) - bad_value ("empty package tags specification"); + parse_list (v, + m.keywords, + ',' /* delim */, + true /* single_word */, + true /* truncate */, + "tags"); } else if (n == "description") { @@ -2514,8 +2563,11 @@ namespace bpkg if (!header_only) { - if (!m.tags.empty ()) - s.next ("tags", concatenate (m.tags)); + if (!m.topics.empty ()) + s.next ("topics", concatenate (m.topics)); + + if (!m.keywords.empty ()) + s.next ("keywords", concatenate (m.keywords, " ")); if (m.description) { diff --git a/libbpkg/manifest.hxx b/libbpkg/manifest.hxx index 01ffa49..9493ee0 100644 --- a/libbpkg/manifest.hxx +++ b/libbpkg/manifest.hxx @@ -645,7 +645,8 @@ namespace bpkg butl::optional priority; std::string summary; std::vector license_alternatives; - strings tags; + strings topics; + strings keywords; butl::optional description; butl::optional description_type; std::vector changes; -- cgit v1.1