#include <iostream>
#include <string>
#include <vector>
#if defined ( DEBUG )
#define DEBUG_CODE( code_to_put_into_source ) { code_to_put_into_source }
#else
#define DEBUG_CODE( code_to_put_into_source )
#endif
#include <libintl.h>
#define _(String) gettext (String)
#include <locale.h>
using namespace std;
template <typename Container>
inline void
stringtok( Container &container, std::string const & in,
const char * const delimiters = " \t\n\r\f\v" )
{
const std::string::size_type len = in.length();
std::string::size_type i = 0;
while ( i < len )
{
i = in.find_first_not_of( delimiters, i );
if ( i == std::string::npos )
{
return;
}
std::string::size_type j = in.find_first_of( delimiters, i );
if ( j == std::string::npos )
{
container.push_back( in.substr(i) );
return;
}
else
{
container.push_back( in.substr( i, j-i ) );
}
i = j + 1;
}
}
int main( void )
{
char * lang = setlocale ( LC_MESSAGES, "" );
cerr << "Lang = " << lang << endl;
bindtextdomain ( "stringtoken", "/usr/share/locale" );
textdomain ( "stringtoken" );
std::vector<std::string> vec_tokens;
const std::string string2parse = _("Today was my birthday. I am 16 years old.");
stringtok( vec_tokens, string2parse, " \n" );
cout << "\n\nString = " << string2parse << "\n\nTokens:\n\n";
ostream_iterator<string> out_iter(cout, "\n" );
copy( vec_tokens.begin(), vec_tokens.end(), out_iter );
cout << endl;
return 0;
}