ATLAS Offline Software
Tokenize.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #ifndef _UTILS_TOKENIZE_H_
6 #define _UTILS_TOKENIZE_H_
7 
8 #include <string>
9 #include <set>
10 
11 namespace top {
23  template <typename Container>
24  void tokenize(const std::string& input, Container& output,
25  const std::string& delimiters = " ", bool trim_empty = false) {
26  const auto size = input.size();
27 
28  std::string::size_type pos {
29  0
30  };
31  std::string::size_type last_pos {
32  0
33  };
34 
35  while (last_pos < size + 1) {
36  pos = input.find_first_of(delimiters, last_pos);
37  if (pos == std::string::npos) {
38  pos = size;
39  }
40 
41  if (pos != last_pos || not trim_empty) {
42  output.emplace_back(input.data() + last_pos, pos - last_pos);
43  }
44 
45  last_pos = pos + 1;
46  }
47  }
48 
52  template <typename Container>
53  void tokenize_set(const std::string& input, Container& output,
54  const std::string& delimiters = " ", bool trim_empty = false) {
55  const auto size = input.size();
56 
57  std::string::size_type pos {
58  0
59  };
60  std::string::size_type last_pos {
61  0
62  };
63 
64  while (last_pos < size + 1) {
65  pos = input.find_first_of(delimiters, last_pos);
66  if (pos == std::string::npos) {
67  pos = size;
68  }
69 
70  if (pos != last_pos || not trim_empty) {
71  output.emplace(input.data() + last_pos, pos - last_pos);
72  }
73 
74  last_pos = pos + 1;
75  }
76  }
77 }
78 
79 #endif /* _UTILS_TOKENIZE_H_ */
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
top::tokenize
void tokenize(const std::string &input, Container &output, const std::string &delimiters=" ", bool trim_empty=false)
Tokenize an input string using a set of delimiters.
Definition: Tokenize.h:24
Container
storage of the time histories of all the cells
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
merge.output
output
Definition: merge.py:17
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
top::tokenize_set
void tokenize_set(const std::string &input, Container &output, const std::string &delimiters=" ", bool trim_empty=false)
Same as tokenize() method, but accepts std::set-like containers, with emplace method.
Definition: Tokenize.h:53