spiegel-keyman/linux/scim_kmfl_imengine/src/stringtok.h
2005-02-09 19:57:03 +00:00

35 lines
879 B
C++

#ifndef __STRINGTOK_H__
#define __STRINGTOK_H__
#include <string>
template <typename Container>
void
stringtok (Container &container, std::string const &in,
const char * const delimiters = " \t\n")
{
const std::string::size_type len = in.length();
std::string::size_type i = 0;
while ( i < len )
{
// eat leading whitespace
i = in.find_first_not_of (delimiters, i);
if (i == std::string::npos)
return; // nothing left but white space
// find the end of the token
std::string::size_type j = in.find_first_of (delimiters, i);
// push token
if (j == std::string::npos) {
container.push_back (in.substr(i));
return;
} else
container.push_back (in.substr(i, j-i));
// set up for next loop
i = j + 1;
}
}
#endif