LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
branchNameComponentChecking.cc
Go to the documentation of this file.
2 #include "boost/algorithm/string.hpp"
4 
5 #include <regex>
6 #include <string>
7 #include <vector>
8 
9 namespace {
10 
11  std::regex const typeRE("^(?:[[:alnum:]]|::)*");
12  std::regex const typeSelectorRE("^(?:[[:alnum:]\\*\\?]|::)*");
13  std::regex const labelRE("^[[:alnum:]#]*");
14  std::regex const labelSelectorRE("^[[:alnum:]#\\*\\?]*");
15  std::regex const processRE("^[[:alnum:]]*");
16  std::regex const processSelectorRE("^[[:alnum:]\\*\\?]*");
17 
18  bool
19  checkBranchNameComponent(std::string const& component,
20  std::string const& designation,
21  std::regex const& re,
22  std::string& errMsg,
23  bool emptyOK = false)
24  {
25  bool result = true;
26  if (component.empty()) {
27  if (!emptyOK) {
28  errMsg += "Illegal empty " + designation + ".\n";
29  }
30  } else {
31  std::smatch sm;
32  result =
33  std::regex_search(component, sm, re) && sm.suffix().str().empty();
34  if (!result) {
35  errMsg += "Illegal character(s) found in " + designation + "\n " +
36  component + '\n' + std::string(2ul + sm.length(), ' ') + '^' +
37  std::string(component.length() - sm.length(), ' ') +
38  "(first infraction marked).\n";
39  }
40  }
41  return result;
42  }
43 } // namespace
44 
46 art::detail::splitToComponents(std::string const& branchName,
47  std::string& errMsg)
48 {
49  std::vector<std::string> parts;
50  boost::split(parts, branchName, boost::is_any_of("_"));
51  if (parts.size() != 4) {
52  errMsg += "Illegal product name specification \"" + branchName + "\".\n";
53  }
54  return BranchKey(std::move(parts[0]),
55  std::move(parts[1]),
56  std::move(parts[2]),
57  std::move(parts[3]));
58 }
59 
60 bool
61 art::detail::checkBranchNameSelector(std::string const& branchNameSelector,
62  std::string& errMsg)
63 {
64  errMsg.clear();
65  auto components = splitToComponents(branchNameSelector, errMsg);
66  return (!errMsg.empty()) || checkBranchNameSelector(components, errMsg);
67 }
68 
69 bool
71  std::string& errMsg)
72 {
73  // Inclusive operation: do all steps.
74  bool result =
76  result = checkModuleLabelSelector(components.moduleLabel_, errMsg) && result;
77  result = checkInstanceNameSelector(components.productInstanceName_, errMsg) &&
78  result;
79  result = checkProcessNameSelector(components.processName_, errMsg) && result;
80  return result;
81 }
82 
83 bool
85  std::string& errMsg)
86 {
87  return checkBranchNameComponent(
88  friendlyName, "friendly name", typeRE, errMsg);
89 }
90 
91 bool
92 art::detail::checkFriendlyNameSelector(std::string const& friendlyNameSelector,
93  std::string& errMsg)
94 {
95  return checkBranchNameComponent(
96  friendlyNameSelector, "friendly name", typeSelectorRE, errMsg);
97 }
98 
99 bool
100 art::detail::checkModuleLabel(std::string const& moduleLabel,
101  std::string& errMsg)
102 {
103  return checkBranchNameComponent(moduleLabel, "module label", labelRE, errMsg);
104 }
105 
106 bool
107 art::detail::checkModuleLabelSelector(std::string const& moduleLabelSelector,
108  std::string& errMsg)
109 {
110  return checkBranchNameComponent(
111  moduleLabelSelector, "module label", labelSelectorRE, errMsg);
112 }
113 
114 bool
115 art::detail::checkInstanceName(std::string const& instanceName,
116  std::string& errMsg)
117 {
118  return checkBranchNameComponent(instanceName,
119  "instance name",
120  processRE, // sic.
121  errMsg,
122  true);
123 }
124 
125 bool
126 art::detail::checkInstanceNameSelector(std::string const& instanceNameSelector,
127  std::string& errMsg)
128 {
129  return checkBranchNameComponent(instanceNameSelector,
130  "instance name",
131  processSelectorRE, // sic.
132  errMsg,
133  true);
134 }
135 
136 bool
137 art::detail::checkProcessName(std::string const& processName,
138  std::string& errMsg)
139 {
140  return checkBranchNameComponent(
141  processName, "process name", processRE, errMsg);
142 }
143 
144 bool
145 art::detail::checkProcessNameSelector(std::string const& processNameSelector,
146  std::string& errMsg)
147 {
148  return checkBranchNameComponent(
149  processNameSelector, "process name", processSelectorRE, errMsg);
150 }
bool checkModuleLabelSelector(std::string const &moduleLabelSelector, std::string &errMsg)
bool checkBranchNameSelector(std::string const &branchNameSelector, std::string &errMsg)
bool checkInstanceNameSelector(std::string const &instanceNameSelector, std::string &errMsg)
BranchKey splitToComponents(std::string const &branchName, std::string &errMsg)
std::string productInstanceName_
Definition: BranchKey.h:45
bool checkInstanceName(std::string const &instanceName, std::string &errMsg)
std::string friendlyClassName_
Definition: BranchKey.h:43
bool checkProcessNameSelector(std::string const &processNameSelector, std::string &errMsg)
bool checkFriendlyNameSelector(std::string const &friendlyNameSelector, std::string &errMsg)
std::string friendlyName(std::string const &iFullName)
bool checkFriendlyName(std::string const &friendlyName, std::string &errMsg)
bool checkProcessName(std::string const &processName, std::string &errMsg)
std::string processName_
Definition: BranchKey.h:46
std::string moduleLabel_
Definition: BranchKey.h:44
bool checkModuleLabel(std::string const &moduleLabel, std::string &errMsg)