cachefilter.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include <apti18n.h>
  11. #include <string>
  12. #include <regex.h>
  13. /*}}}*/
  14. namespace APT {
  15. namespace CacheFilter {
  16. PackageNameMatchesRegEx::PackageNameMatchesRegEx(std::string const &Pattern) {/*{{{*/
  17. pattern = new regex_t;
  18. int const Res = regcomp(pattern, Pattern.c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB);
  19. if (Res == 0)
  20. return;
  21. delete pattern;
  22. pattern = NULL;
  23. char Error[300];
  24. regerror(Res, pattern, Error, sizeof(Error));
  25. _error->Error(_("Regex compilation error - %s"), Error);
  26. }
  27. /*}}}*/
  28. bool PackageNameMatchesRegEx::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/
  29. if (unlikely(pattern == NULL))
  30. return false;
  31. else
  32. return regexec(pattern, Pkg.Name(), 0, 0, 0) == 0;
  33. }
  34. /*}}}*/
  35. bool PackageNameMatchesRegEx::operator() (pkgCache::GrpIterator const &Grp) {/*{{{*/
  36. if (unlikely(pattern == NULL))
  37. return false;
  38. else
  39. return regexec(pattern, Grp.Name(), 0, 0, 0) == 0;
  40. }
  41. /*}}}*/
  42. PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/
  43. if (pattern == NULL)
  44. return;
  45. regfree(pattern);
  46. delete pattern;
  47. }
  48. /*}}}*/
  49. }
  50. }