diff options
author | Michael Vogt <michael.vogt@ubuntu.com> | 2010-07-29 11:37:05 +0200 |
---|---|---|
committer | Michael Vogt <michael.vogt@ubuntu.com> | 2010-07-29 11:37:05 +0200 |
commit | 1b8ba3ba050f01db27f1ddc0e5b280b2fccd9fb9 (patch) | |
tree | 4c95c5ad0b62ae2e3ad155a89f3997efe5109c28 /apt-pkg/cachefilter.cc | |
parent | 15032eec2d508df3c63b532be22f488d240159a2 (diff) | |
parent | 3de4647b39216259678f40f4bf6e8122acd923b5 (diff) |
merged lp:~donkult/apt/sid
Diffstat (limited to 'apt-pkg/cachefilter.cc')
-rw-r--r-- | apt-pkg/cachefilter.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc new file mode 100644 index 000000000..8f0725ea3 --- /dev/null +++ b/apt-pkg/cachefilter.cc @@ -0,0 +1,54 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/** \file cachefilter.h + Collection of functor classes */ + /*}}}*/ +// Include Files /*{{{*/ +#include <apt-pkg/cachefilter.h> +#include <apt-pkg/error.h> +#include <apt-pkg/pkgcache.h> + +#include <apti18n.h> + +#include <string> + +#include <regex.h> + /*}}}*/ +namespace APT { +namespace CacheFilter { +PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) {/*{{{*/ + pattern = new regex_t; + int const Res = regcomp(pattern, Pattern.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB); + if (Res == 0) + return; + + delete pattern; + pattern = NULL; + char Error[300]; + regerror(Res, pattern, Error, sizeof(Error)); + _error->Error(_("Regex compilation error - %s"), Error); +} + /*}}}*/ +bool PackageNameMatchesRegEx::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/ + if (unlikely(pattern == NULL)) + return false; + else + return regexec(pattern, Pkg.Name(), 0, 0, 0) == 0; +} + /*}}}*/ +bool PackageNameMatchesRegEx::operator() (pkgCache::GrpIterator const &Grp) {/*{{{*/ + if (unlikely(pattern == NULL)) + return false; + else + return regexec(pattern, Grp.Name(), 0, 0, 0) == 0; +} + /*}}}*/ +PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/ + if (pattern == NULL) + return; + regfree(pattern); + delete pattern; +} + /*}}}*/ +} +} |