CMS 3D CMS Logo

Filter.cc
Go to the documentation of this file.
2 #include <functional>
3 #include <regex>
4 #include <iostream>
5 
6 using namespace std;
7 
8 namespace cms {
9  namespace dd {
10 
11  bool compareEqual(string_view node, string_view name) {
12  if(!isRegex(name)) {
13  return (name == node);
14  } else {
15  if(name.front() != node.front())
16  return false;
17  regex pattern({name.data(), name.size()});
18  return regex_match(begin(node), end(node), pattern);
19  }
20  }
21 
22  bool accepted(vector<string_view> const& names, string_view node) {
23  return (find_if(begin(names), end(names),
24  [&](const auto& n) -> bool { return compareEqual(node, n); })
25  != end(names));
26  }
27 
28  int contains(string_view input, string_view needle) {
29  auto const& it = search(begin(input), end(input),
30  default_searcher(begin(needle), end(needle)));
31  if(it != end(input)) {
32  return (it - begin(input));
33  }
34  return -1;
35  }
36 
37  bool isRegex(string_view input) {
38  return ((contains(input, "*") != -1) ||
39  (contains(input, ".") != -1));
40  }
41 
42  string_view realTopName(string_view input) {
43  string_view v = input;
44  auto first = v.find_first_of("//");
45  v.remove_prefix(min(first+2, v.size()));
46  return v;
47  }
48 
49  vector<string_view>
50  split(string_view str, const char* delims) {
51  vector<string_view> ret;
52 
54  auto pos = str.find_first_of(delims, start);
55  while(pos != string_view::npos) {
56  if(pos != start) {
57  ret.emplace_back(str.substr(start, pos - start));
58  }
59  start = pos + 1;
60  pos = str.find_first_of(delims, start);
61  }
62  if(start < str.length())
63  ret.emplace_back(str.substr(start, str.length() - start));
64  return ret;
65  }
66  }
67 }
Definition: start.py:1
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:314
vector< string_view > split(string_view str, const char *delims)
Definition: Filter.cc:50
bool isRegex(string_view input)
Definition: Filter.cc:37
uint16_t size_type
const std::string names[nVars_]
static std::string const input
Definition: EdmProvDump.cc:48
#define end
Definition: vmac.h:39
T min(T a, T b)
Definition: MathUtil.h:58
Namespace of DDCMS conversion namespace.
bool compareEqual(string_view node, string_view name)
Definition: Filter.cc:11
int contains(string_view input, string_view needle)
Definition: Filter.cc:28
bool accepted(vector< string_view > const &names, string_view node)
Definition: Filter.cc:22
#define begin
Definition: vmac.h:32
#define str(s)
string_view realTopName(string_view input)
Definition: Filter.cc:42