ParameterSetImplHelpers.cc
Go to the documentation of this file.
2 #include "boost/algorithm/string.hpp"
5 #include "fhiclcpp/exception.h"
6 
7 #include <algorithm>
8 #include <regex>
9 
10 namespace {
11  std::regex const reBrackets{R"((\]\[|\[|\]))"};
12 }
13 
14 namespace fhicl::detail {
15 
16  Keys
18  {
19  std::vector<std::string> keys;
20  boost::algorithm::split(keys, key, boost::algorithm::is_any_of("."));
21 
22  // Remove empty keys
23  keys.erase(std::remove(keys.begin(), keys.end(), ""), keys.end());
24 
25  if (keys.empty())
26  throw fhicl::exception(fhicl::cant_find, "vacuous key");
27 
28  std::string const last = keys.back();
29  keys.pop_back();
30 
31  return Keys{keys, last};
32  }
33 
36  {
37  // Split "name[0][5][1]" according to delimiters "][", "[", and "]"
38  // to give {"name","0","5","1"};
39  auto tokens = cet::split_by_regex(key, reBrackets);
40 
41  auto const name = tokens.front();
42  tokens.erase(tokens.begin());
43 
44  std::vector<std::size_t> indices;
46  tokens, std::back_inserter(indices), [](std::string const& index) {
47  return std::stoul(index);
48  });
49  return SequenceKey{name, indices};
50  }
51 }
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
Keys get_names(std::string const &key)
std::vector< std::string > split_by_regex(std::string const &str, std::regex const &reDelimSet)
def key(type, name=None)
Definition: graph.py:13
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
auto transform_all(Container &, OutputIt, UnaryOp)
SequenceKey get_sequence_indices(std::string const &key)
void split(std::string const &s, char c, OutIter dest)
Definition: split.h:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33