日本語のsplit

perlphpはなにがいいって正規表現とかそういう文字列処理に優れているところなんですよね。
C++は文字列苦手なんですが、最近紹介してるboostというライブラリががんばってくれています。
とりあえず日本語の切り分けをするプログラムを組んだので紹介。

using namespace std;

wstring str = L"ファイト,だよ☆";

typedef boost::char_separator<wchar_t> Separator;
typedef boost::tokenizer<Separator, wstring::const_iterator, wstring> Tokenizer;
Separator sep(L",");
Tokenizer tok(str, sep);

for (Tokenizer::iterator it = tok.begin(); it != tok.end(); it++ )
{
	std::wstring str = *it;
	cout<<str<<endl;
}

これをつかってこんなプログラムを書いてみた。

str = L"ファイト,だよ☆";
typedef boost::char_separator<wchar_t> Separator;
typedef boost::tokenizer<Separator, wstring::const_iterator, wstring> Tokenizer;
Separator sep(L",");
Tokenizer tok(str, sep);

for (Tokenizer::iterator it = tok.begin(); it != tok.end(); it++ )
{
	std::wstring str = *it;
	font->Render(str.c_str());
	glTranslatef(0.0,-1.0,0.0);
}
glPopMatrix();