TF++, Miscellaneous classes and modules in C++:

◆ gen_split()

template<class C >
void tfxx::string::gen_split ( C &  v,
const std::string &  s,
const std::string &  delimiter = " ",
const bool &  dropdelimiter = false 
)

template #tf:gen_split#:

The following takes a string and splits it into substrings delimited by #delimiter#. The resulting substrings will be written into a container of strings.

Neither the template mechanism nor the linker mechanism linker is able to deduce the correct function definition from the return value. Hence we have to use the container class template parameter in the functions formal parameter list.

This is the inverse operation to #tf::join#.

Parameters
vsequence container that will receive the substrings
sstring to be split into substrings
delimiterstring sequence that intersects substrings
dropdelimiterif #true# the delimiter itself will be excluded from the output
Author
Thomas Forbriger
Version
V1.0 (#$Revision: 1.4 $
Date
2009-11-11 12:34:04

#) split string into substrings

See also
join
split

Definition at line 112 of file stringfunc.h.

Referenced by main(), range(), rangelist(), and split().

115  {
116  v.clear();
117  if (!s.empty()) {
118  std::string::size_type posend=0, pos=0;
119  std::string::size_type len=0;
120  while (posend!=std::string::npos) {
121  posend=s.find(delimiter, pos);
122  len=posend-pos;
123  if (dropdelimiter){
124  v.push_back(s.substr(pos, len));
125  if (posend!=std::string::npos) { len+=delimiter.length(); }
126  } else {
127  if (posend!=std::string::npos) { len+=delimiter.length(); }
128  v.push_back(s.substr(pos, len));
129  }
130  pos+=len;
131  }
132  }
133  }
Here is the caller graph for this function: