diff options
Diffstat (limited to 'apt-pkg/cachefilter-patterns.h')
-rw-r--r-- | apt-pkg/cachefilter-patterns.h | 145 |
1 files changed, 142 insertions, 3 deletions
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index d37da815f..4eeb68594 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -39,6 +39,8 @@ struct PatternTreeParser size_t start = 0; size_t end = 0; + explicit Node(size_t start = 0, size_t end = 0) : start(start), end(end) {} + virtual std::ostream &render(std::ostream &os) { return os; }; std::nullptr_t error(std::string message); }; @@ -71,7 +73,7 @@ struct PatternTreeParser struct State { - off_t offset = 0; + size_t offset = 0; }; APT::StringView sentence; @@ -90,11 +92,18 @@ struct PatternTreeParser /// There may not be anything before or after the pattern, except for /// whitespace. std::unique_ptr<Node> parseTop(); + std::unique_ptr<Node> parse(); // public for test cases only private: - std::unique_ptr<Node> parse(); + std::unique_ptr<Node> parseOr(); + std::unique_ptr<Node> parseAnd(); + std::unique_ptr<Node> parseUnary(); + std::unique_ptr<Node> parsePrimary(); + std::unique_ptr<Node> parseGroup(); std::unique_ptr<Node> parsePattern(); - std::unique_ptr<Node> parseWord(); + std::unique_ptr<Node> parseShortPattern(); + std::unique_ptr<Node> parseArgument(bool shrt); + std::unique_ptr<Node> parseWord(bool shrt); std::unique_ptr<Node> parseQuotedWord(); }; @@ -117,6 +126,21 @@ namespace Patterns { using namespace APT::CacheFilter; +/** \brief Basic helper class for matching regex */ +class BaseRegexMatcher +{ + regex_t *pattern; + + public: + BaseRegexMatcher(std::string const &string); + ~BaseRegexMatcher(); + bool operator()(const char *cstring); + bool operator()(std::string const &string) + { + return (*this)(string.c_str()); + } +}; + struct PackageIsAutomatic : public PackageMatcher { pkgCacheFile *Cache; @@ -229,6 +253,121 @@ struct PackageIsVirtual : public PackageMatcher return Pkg->VersionList == 0; } }; + +struct VersionAnyMatcher : public Matcher +{ + bool operator()(pkgCache::GrpIterator const &Grp) override { return false; } + bool operator()(pkgCache::VerIterator const &Ver) override = 0; + bool operator()(pkgCache::PkgIterator const &Pkg) override + { + for (auto Ver = Pkg.VersionList(); not Ver.end(); Ver++) + { + if ((*this)(Ver)) + return true; + } + return false; + } +}; + +struct VersionIsAllVersions : public Matcher +{ + std::unique_ptr<APT::CacheFilter::Matcher> base; + VersionIsAllVersions(std::unique_ptr<APT::CacheFilter::Matcher> base) : base(std::move(base)) {} + bool operator()(pkgCache::GrpIterator const &) override { return false; } + bool operator()(pkgCache::VerIterator const &Ver) override + { + return (*base)(Ver); + } + bool operator()(pkgCache::PkgIterator const &Pkg) override + { + for (auto Ver = Pkg.VersionList(); not Ver.end(); Ver++) + { + if (not(*this)(Ver)) + return false; + } + return true; + } +}; + +struct VersionIsAnyVersion : public VersionAnyMatcher +{ + std::unique_ptr<APT::CacheFilter::Matcher> base; + VersionIsAnyVersion(std::unique_ptr<APT::CacheFilter::Matcher> base) : base(std::move(base)) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + return (*base)(Ver); + } +}; + +struct VersionIsArchive : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsArchive(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + for (auto VF = Ver.FileList(); not VF.end(); VF++) + { + if (VF.File().Archive() && matcher(VF.File().Archive())) + return true; + } + return false; + } +}; + +struct VersionIsOrigin : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsOrigin(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + for (auto VF = Ver.FileList(); not VF.end(); VF++) + { + if (VF.File().Origin() && matcher(VF.File().Origin())) + return true; + } + return false; + } +}; + +struct VersionIsSection : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsSection(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + return matcher(Ver.Section()); + } +}; + +struct VersionIsSourcePackage : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsSourcePackage(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + return matcher(Ver.SourcePkgName()); + } +}; + +struct VersionIsSourceVersion : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsSourceVersion(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + return matcher(Ver.SourceVerStr()); + } +}; + +struct VersionIsVersion : public VersionAnyMatcher +{ + BaseRegexMatcher matcher; + VersionIsVersion(std::string const &pattern) : matcher(pattern) {} + bool operator()(pkgCache::VerIterator const &Ver) override + { + return matcher(Ver.VerStr()); + } +}; } // namespace Patterns } // namespace Internal } // namespace APT |