2 * Same as stringtok_h.txt, but doesn't (visiably) use C functions.
7 // The std:: prefix is not used here, for readability, and a line like
8 // "using namespace std;" is dangerous to have in a header file.
10 template <typename Container>
12 stringtok (Container &container, string const &in,
13 const char * const delimiters = " \t\n")
15 const string::size_type len = in.length();
16 string::size_type i = 0;
20 // eat leading whitespace
21 i = in.find_first_not_of (delimiters, i);
22 if (i == string::npos)
23 return; // nothing left but white space
25 // find the end of the token
26 string::size_type j = in.find_first_of (delimiters, i);
29 if (j == string::npos) {
30 container.push_back (in.substr(i));
33 container.push_back (in.substr(i, j-i));
35 // set up for next loop