From 5c950263e9ea902e86030b5fd3a8c6b0760e7539 Mon Sep 17 00:00:00 2001 From: Ciaran McCreesh Date: Mon, 4 Apr 2011 14:54:38 +0100 Subject: [.key~value] operator --- doc/configuration/specs.html.part | 8 +-- paludis/package_dep_spec_constraint.cc | 94 ++++++++++++++++++++++++++++++++-- paludis/package_dep_spec_constraint.se | 1 + paludis/user_dep_spec.cc | 3 +- 4 files changed, 96 insertions(+), 10 deletions(-) diff --git a/doc/configuration/specs.html.part b/doc/configuration/specs.html.part index ad3758eca..40833f3de 100644 --- a/doc/configuration/specs.html.part +++ b/doc/configuration/specs.html.part @@ -46,10 +46,10 @@ the following order:

  • [.key=value]: Match only if the specified metadata key has a particular exact value. Only works for simple values, sets and sequences, not spec trees and other complex compound keys. If < is used in place of =, for numeric values a less-than comparison is used, and for sets, sequences and spec trees, - a match occurs if any member of the set or sequence is equal to the value. Similarly if > is used, - for numeric values a greater-than comparison is used; it does not match for other types of values. As above, the key - may be a raw name or a dollar-prefixed role name, and may be prefixed with :: for checking repository - metadata.
  • + a match occurs if any member of the set or sequence is equal to the value. If > is used, + for numeric values a greater-than comparison is used; it does not match for other types of values. If ~ + is used, a substring match is performed. As above, the key may be a raw name or a dollar-prefixed role name, and + may be prefixed with :: for checking repository metadata.

    Repository requirements are in the form to, from-> or ::from->to. The diff --git a/paludis/package_dep_spec_constraint.cc b/paludis/package_dep_spec_constraint.cc index 5db0b2b47..68b163959 100644 --- a/paludis/package_dep_spec_constraint.cc +++ b/paludis/package_dep_spec_constraint.cc @@ -481,6 +481,8 @@ namespace { case kco_equals: return pattern == stringify(k.value().seconds()); + case kco_tilde: + return std::string::npos != stringify(k.value().seconds()).find(pattern); case kco_less_than: return k.value().seconds() < destringify(pattern); case kco_greater_than: @@ -495,22 +497,74 @@ namespace bool visit(const MetadataValueKey & k) const { - return pattern == stringify(k.value()); + switch (op) + { + case kco_equals: + return pattern == stringify(k.value()); + case kco_tilde: + return std::string::npos != stringify(k.value()).find(pattern); + case kco_less_than: + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; } bool visit(const MetadataValueKey & k) const { - return pattern == stringify(k.value()); + switch (op) + { + case kco_equals: + return pattern == stringify(k.value()); + case kco_tilde: + return std::string::npos != stringify(k.value()).find(pattern); + case kco_less_than: + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; } bool visit(const MetadataValueKey & k) const { - return pattern == stringify(k.value()); + switch (op) + { + case kco_equals: + return pattern == stringify(k.value()); + case kco_tilde: + return std::string::npos != stringify(k.value()).find(pattern); + case kco_less_than: + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; } bool visit(const MetadataValueKey & k) const { - return pattern == stringify(k.value()); + switch (op) + { + case kco_equals: + return pattern == stringify(k.value()); + case kco_tilde: + return std::string::npos != stringify(k.value()).find(pattern); + case kco_less_than: + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; } bool visit(const MetadataValueKey & k) const @@ -519,6 +573,8 @@ namespace { case kco_equals: return pattern == stringify(k.value()); + case kco_tilde: + return std::string::npos != stringify(k.value()).find(pattern); case kco_less_than: return k.value() < destringify(pattern); case kco_greater_than: @@ -551,6 +607,7 @@ namespace case kco_greater_than: case kco_question: + case kco_tilde: case last_kco: break; } @@ -560,7 +617,20 @@ namespace bool visit(const MetadataValueKey > & k) const { - return pattern == stringify(*k.value()); + switch (op) + { + case kco_equals: + return pattern == stringify(*k.value()); + case kco_tilde: + return std::string::npos != stringify(*k.value()).find(pattern); + case kco_less_than: + case kco_greater_than: + case kco_question: + case last_kco: + break; + } + + return false; } bool visit(const MetadataSpecTreeKey & s) const @@ -572,6 +642,7 @@ namespace case kco_less_than: return s.value()->top()->accept_returning(SpecTreeSearcher(env, id, pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -590,6 +661,7 @@ namespace case kco_less_than: return s.value()->top()->accept_returning(SpecTreeSearcher(env, id, pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -608,6 +680,7 @@ namespace case kco_less_than: return s.value()->top()->accept_returning(SpecTreeSearcher(env, id, pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -626,6 +699,7 @@ namespace case kco_less_than: return s.value()->top()->accept_returning(SpecTreeSearcher(env, id, pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -644,6 +718,7 @@ namespace case kco_less_than: return s.value()->top()->accept_returning(SpecTreeSearcher(env, id, pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -662,6 +737,7 @@ namespace case kco_less_than: return s.value()->top()->accept_returning(SpecTreeSearcher(env, id, pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -680,6 +756,7 @@ namespace case kco_less_than: return s.value()->top()->accept_returning(SpecTreeSearcher(env, id, pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -698,6 +775,7 @@ namespace case kco_less_than: return s.value()->top()->accept_returning(SpecTreeSearcher(env, id, pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -717,6 +795,7 @@ namespace return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), StringifyEqual(pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -738,6 +817,7 @@ namespace indirect_iterator(s.value()->end()), StringifyEqual(pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -757,6 +837,7 @@ namespace return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), StringifyEqual(pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -776,6 +857,7 @@ namespace return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), StringifyEqual(pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -800,6 +882,7 @@ namespace return s.value()->end() != std::find_if(s.value()->begin(), s.value()->end(), StringifyEqual(pattern)); + case kco_tilde: case kco_greater_than: case kco_question: case last_kco: @@ -1024,6 +1107,7 @@ KeyConstraint::as_raw_string() const switch (operation()) { case kco_equals: s << "=" << pattern(); break; + case kco_tilde: s << "~" << pattern(); break; case kco_less_than: s << "<" << pattern(); break; case kco_greater_than: s << ">" << pattern(); break; case kco_question: s << "?"; break; diff --git a/paludis/package_dep_spec_constraint.se b/paludis/package_dep_spec_constraint.se index 54982f847..f224c1b1a 100644 --- a/paludis/package_dep_spec_constraint.se +++ b/paludis/package_dep_spec_constraint.se @@ -6,6 +6,7 @@ make_enum_KeyConstraintOperation() prefix kco key kco_equals "An = constraint" + key kco_tilde "A ~ constraint" key kco_less_than "A less than constraint" key kco_greater_than "A greater than constraint" key kco_question "A question constraint" diff --git a/paludis/user_dep_spec.cc b/paludis/user_dep_spec.cc index 37f1c12c3..7f8887384 100644 --- a/paludis/user_dep_spec.cc +++ b/paludis/user_dep_spec.cc @@ -326,7 +326,7 @@ paludis::user_version_spec_options() std::tuple paludis::parse_user_key_constraint(const std::string & s) { - std::string::size_type p(s.find_first_of("=<>?")); + std::string::size_type p(s.find_first_of("=<>?~")); if (std::string::npos == p) throw PackageDepSpecError("[." + s + "] contains no operator"); @@ -348,6 +348,7 @@ paludis::parse_user_key_constraint(const std::string & s) switch (s.at(p)) { case '=': op = kco_equals; break; + case '~': op = kco_tilde; break; case '<': op = kco_less_than; break; case '>': op = kco_greater_than; break; default: -- cgit v1.2.3