]> git.saurik.com Git - apt.git/blob - apt-pkg/cachefilter.cc
* apt-pkg/contrib/cdromutl.cc:
[apt.git] / apt-pkg / cachefilter.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /** \file cachefilter.h
4 Collection of functor classes */
5 /*}}}*/
6 // Include Files /*{{{*/
7 #include <apt-pkg/cachefilter.h>
8 #include <apt-pkg/error.h>
9 #include <apt-pkg/pkgcache.h>
10
11 #include <apti18n.h>
12
13 #include <string>
14
15 #include <regex.h>
16 /*}}}*/
17 namespace APT {
18 namespace CacheFilter {
19 PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) {/*{{{*/
20 pattern = new regex_t;
21 int const Res = regcomp(pattern, Pattern.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
22 if (Res == 0)
23 return;
24
25 delete pattern;
26 pattern = NULL;
27 char Error[300];
28 regerror(Res, pattern, Error, sizeof(Error));
29 _error->Error(_("Regex compilation error - %s"), Error);
30 }
31 /*}}}*/
32 bool PackageNameMatchesRegEx::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/
33 if (unlikely(pattern == NULL))
34 return false;
35 else
36 return regexec(pattern, Pkg.Name(), 0, 0, 0) == 0;
37 }
38 /*}}}*/
39 bool PackageNameMatchesRegEx::operator() (pkgCache::GrpIterator const &Grp) {/*{{{*/
40 if (unlikely(pattern == NULL))
41 return false;
42 else
43 return regexec(pattern, Grp.Name(), 0, 0, 0) == 0;
44 }
45 /*}}}*/
46 PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/
47 if (pattern == NULL)
48 return;
49 regfree(pattern);
50 delete pattern;
51 }
52 /*}}}*/
53 }
54 }