#include <iostream>
#include <vector>
#include <locale>
#include <sstream>
// This ctype facet classifies .^:;\n but not anything else as whitespace
struct my_whitespace : std::ctype<char> {
static const mask* make_table()
{
// make a copy of the "C" locale table
static std::vector<mask> v(classic_table(), classic_table() + table_size);
// these will be whitespace
v['.'] |= space;
v['^'] |= space;
v[':'] |= space;
v[';'] |= space;
// space and tab won't be whitespace
v[' '] &= ~space;
v['\t'] &= ~space;
return &v[0];
}
my_whitespace(std::size_t refs = 0) :
std::ctype<char>(make_table(), false, refs) {}
};
int main()
{
std::string in = "a:b.c;d\ne^f";
std::istringstream s(in);
s.imbue(std::locale(s.getloc(), new my_whitespace()));
std::string token;
while(s >> token)
std::cout << " " << token<< '\n';
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bG9jYWxlPgojaW5jbHVkZSA8c3N0cmVhbT4KIAovLyBUaGlzIGN0eXBlIGZhY2V0IGNsYXNzaWZpZXMgLl46O1xuIGJ1dCBub3QgYW55dGhpbmcgZWxzZSBhcyB3aGl0ZXNwYWNlCnN0cnVjdCBteV93aGl0ZXNwYWNlIDogc3RkOjpjdHlwZTxjaGFyPiB7CiAgICBzdGF0aWMgY29uc3QgbWFzayogbWFrZV90YWJsZSgpCiAgICB7CiAgICAgICAgLy8gbWFrZSBhIGNvcHkgb2YgdGhlICJDIiBsb2NhbGUgdGFibGUKICAgICAgICBzdGF0aWMgc3RkOjp2ZWN0b3I8bWFzaz4gdihjbGFzc2ljX3RhYmxlKCksICBjbGFzc2ljX3RhYmxlKCkgKyB0YWJsZV9zaXplKTsKICAgICAgICAvLyB0aGVzZSB3aWxsIGJlIHdoaXRlc3BhY2UKICAgICAgICB2WycuJ10gfD0gIHNwYWNlOyAKICAgICAgICB2WydeJ10gfD0gIHNwYWNlOyAKICAgICAgICB2Wyc6J10gfD0gIHNwYWNlOyAKICAgICAgICB2Wyc7J10gfD0gIHNwYWNlOyAKICAgICAgICAvLyBzcGFj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