diff --git a/include/spiffing/categorydata.h b/include/spiffing/categorydata.h index 3b79f7b..53670f9 100644 --- a/include/spiffing/categorydata.h +++ b/include/spiffing/categorydata.h @@ -42,6 +42,9 @@ namespace Spiffing { void compile(Spif const &); bool matches(Label const &) const; void fixup(Label &) const; + std::set const & cats() const { + return m_cats; + } private: std::set m_cats; std::string m_tagSetRef; diff --git a/src/categorygroup.cc b/src/categorygroup.cc index 50491d9..840acc1 100644 --- a/src/categorygroup.cc +++ b/src/categorygroup.cc @@ -26,6 +26,7 @@ SOFTWARE. #include #include #include +#include using namespace Spiffing; @@ -34,19 +35,20 @@ CategoryGroup::CategoryGroup(OperationType opType) : m_opType(opType) {} bool CategoryGroup::matches(Label const & l) const { bool found{false}; for (auto const & cd : m_categoryData) { - if (cd->matches(l)) { - switch (m_opType) { - case OperationType::onlyOne: - if (found) return false; - break; - case OperationType::oneOrMore: - return true; - case OperationType::all: - ; + for (auto const & cat : cd->cats()) { + if (l.hasCategory(cat)) { + switch (m_opType) { + case OperationType::onlyOne: + if (found) return false; + break; + case OperationType::oneOrMore: + return true; + case OperationType::all:; + } + found = true; + } else if (m_opType == OperationType::all) { + return false; } - found = true; - } else if (m_opType == OperationType::all) { - return false; } } return found; diff --git a/test-data/food-policy.xml b/test-data/food-policy.xml index 9d43206..80c1b54 100644 --- a/test-data/food-policy.xml +++ b/test-data/food-policy.xml @@ -78,7 +78,13 @@ - + + + + + + +