CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
split.h File Reference
#include <string>

Go to the source code of this file.

Functions

template<typename E , typename C >
size_t split (std::basic_string< E > const &s, C &container, E const delimiter, bool keepBlankFields=true)
 

Function Documentation

template<typename E , typename C >
size_t split ( std::basic_string< E > const &  s,
C &  container,
E const  delimiter,
bool  keepBlankFields = true 
)

Definition at line 22 of file split.h.

References end, first, and n.

26 {
27  size_t n = 0;
28  typename std::basic_string<E>::const_iterator it = s.begin(), end = s.end(), first;
29  for (first = it; it != end; ++it)
30  {
31  // Examine each character and if it matches the delimiter
32  if (delimiter == *it)
33  {
34  if (keepBlankFields || first != it)
35  {
36  // extract the current field from the string and
37  // append the current field to the given container
38  container.push_back(std::basic_string<E>(first, it));
39  ++n;
40 
41  // skip the delimiter
42  first = it + 1;
43  }
44  else
45  {
46  ++first;
47  }
48  }
49  }
50  if (keepBlankFields || first != it)
51  {
52  // extract the last field from the string and
53  // append the last field to the given container
54  container.push_back(std::basic_string<E>(first, it));
55  ++n;
56  }
57  return n;
58 }
#define end
Definition: vmac.h:38
bool first
Definition: L1TdeRCT.cc:94