CBMC
prefix_filter.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Prefix Filtering
4 
5 Author: Peter Schrammel
6 
7 \*******************************************************************/
8 
11 
12 #include "prefix_filter.h"
13 
14 #include <algorithm>
15 
16 #include "prefix.h"
17 
19  std::vector<std::string> included_prefixes,
20  std::vector<std::string> excluded_prefixes)
21  : included_prefixes(std::move(included_prefixes)),
22  excluded_prefixes(std::move(excluded_prefixes))
23 {
24 }
25 
26 bool prefix_filtert::operator()(const std::string &value) const
27 {
28  if(!included_prefixes.empty())
29  {
30  // We don't include everything, so let's check whether value is included.
31  const bool matches_included = std::any_of(
32  included_prefixes.begin(),
33  included_prefixes.end(),
34  [value](const std::string &prefix) { return has_prefix(value, prefix); });
35  if(!matches_included)
36  return false;
37  }
38 
39  // We know it's included so let's check whether it's excluded.
40  const bool matches_excluded = std::any_of(
41  excluded_prefixes.begin(),
42  excluded_prefixes.end(),
43  [value](const std::string &prefix) { return has_prefix(value, prefix); });
44  return !matches_excluded;
45 }
std::vector< std::string > included_prefixes
Definition: prefix_filter.h:33
prefix_filtert(std::vector< std::string > included_prefixes, std::vector< std::string > excluded_prefixes)
bool operator()(const std::string &value) const
Return true iff value matches a prefix in included_prefixes, but doesn't match a prefix in excluded_p...
std::vector< std::string > excluded_prefixes
Definition: prefix_filter.h:34
Prefix Filtering.