Skip to content

Instantly share code, notes, and snippets.

@dgodfrey206
Created November 14, 2014 00:45
Show Gist options
  • Save dgodfrey206/af594bb14f21eaa93345 to your computer and use it in GitHub Desktop.
Save dgodfrey206/af594bb14f21eaa93345 to your computer and use it in GitHub Desktop.
Facet that ignores all alphabetical characters
#include <iostream>
#include <sstream>
class whitespace_fmt : public std::ctype<char>
{
mask table[table_size];
public:
whitespace_fmt(size_t refs = 0)
: std::ctype<char>(table, false, refs)
{
for (auto c : "abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWYZ")
{
table[static_cast<int>(c)] |= space;
}
}
};
int main()
{
std::stringstream ss("abcdef12345ghij");
ss.imbue(std::locale(ss.getloc(), new whitespace_fmt));
std::string str;
ss >> str;
std::cout << str << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment