FileNameComponents.cc
Go to the documentation of this file.
2 #include "boost/regex.hpp"
3 
4 #include <cassert>
5 #include <iomanip>
6 #include <sstream>
7 
8 namespace art::detail {
9 
10  void
12  std::string const& digitFormat)
13  {
14  components_.emplace_back(prefix, digitFormat);
15  }
16 
17  void
19  {
20  suffix_ = move(suffix);
21  }
22 
23  bool
25  {
26  if (components_.size() < fnc.components_.size()) {
27  return true;
28  }
29  if (components_.size() > fnc.components_.size()) {
30  return false;
31  }
32 
33  assert(components_.size() == fnc.components_.size());
34  auto b1 = cbegin(components_), e1 = cend(components_);
35  auto b2 = cbegin(fnc.components_);
36  for (; b1 != e1; ++b1, ++b2) {
37  if (b1->first < b2->first)
38  return true;
39  }
40  assert(b2 == cend(fnc.components_));
41  return false;
42  }
43 
46  {
47  std::ostringstream num_str;
48  for (auto const& pr : components_) {
49  auto const& prefix = pr.first;
50  auto const& specifier = pr.second;
51  num_str << prefix;
52  if (!specifier.empty()) { // Zero-filling.
53  num_str << std::setfill('0') << std::setw(std::stoul(specifier));
54  }
55  num_str << index;
56  }
57  num_str << suffix_;
58  return num_str.str();
59  }
60 
63  {
65 
66  boost::smatch match;
67  auto sid = cbegin(pattern), se = cend(pattern);
68  while (boost::regex_search(
69  sid,
70  se,
71  match,
72  boost::regex{"%(\\d+)?#", boost::regex_constants::ECMAScript})) {
73  assert(match.size() == 2);
74  // Subexpressions:
75  // 0. Entire matched expression
76  // 1. Possible fill format digits for numeric substitution.
77  result.add(match.prefix(), match[1].str());
78  sid = match[0].second;
79  }
80  // Get remaining characters of filename
81  result.setSuffix(std::string(sid, se));
82  return result;
83  }
84 }
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:87
static QCString result
std::string string
Definition: nybbler.cc:12
bool operator<(FileNameComponents const &fnc) const
void setSuffix(std::string suffix)
def move(depos, offset)
Definition: depos.py:107
FileNameComponents componentsFromPattern(std::string const &pattern)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
std::string fileNameWithIndex(std::size_t index) const
void add(std::string const &prefix, std::string const &digitFormat)
std::string pattern
Definition: regex_t.cc:35
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
Definition: StdUtils.h:82
std::vector< std::pair< std::string, std::string > > components_
Q_EXPORT QTSManip setfill(int f)
Definition: qtextstream.h:337
Definition: se.py:1