wboundary.cpp
Example of using boundary iterator over wide strings
#include <boost/locale.hpp>
#include <iostream>
#include <cassert>
#include <ctime>
#ifndef BOOST_NO_SWPRINTF
int main(int argc,char **argv)
{
using namespace boost::locale;
using namespace std;
std::ios_base::sync_with_stdio(false);
generator gen;
locale::global(locale(""));
locale loc;
if(argc == 1)
loc=gen("");
else if(argc == 2)
loc=gen(argv[1]);
else
loc=gen(argv[1],argv[2]);
locale::global(loc);
wcout.imbue(loc);
wstring text=L"Hello World! あにま! Linux2.6 and Windows7 is word and number. שָלוֹם עוֹלָם!";
wcout<<text<<endl;
typedef boundary::token_iterator<std::wstring::iterator> iter_type;
typedef boundary::mapping<iter_type> mapping_type;
mapping_type index(boundary::word,text.begin(),text.end());
iter_type p,e;
for(p=index.begin(),e=index.end();p!=e;++p) {
wcout<<L"Part ["<<*p<<L"] has ";
if(p.mark() & boundary::word_number)
wcout<<L"number ";
if(p.mark() & boundary::word_letter)
wcout<<L"letter ";
if(p.mark() & boundary::word_kana)
wcout<<L"kana characters ";
if(p.mark() & boundary::word_ideo)
wcout<<L"ideographic characters ";
wcout<<endl;
}
index.map(boundary::character,text.begin(),text.end());
for(p=index.begin(),e=index.end();p!=e;++p) {
wcout<<L"|" <<*p ;
}
wcout<<L"|\n\n";
index.map(boundary::line,text.begin(),text.end());
for(p=index.begin(),e=index.end();p!=e;++p) {
wcout<<L"|" <<*p ;
}
wcout<<L"|\n\n";
index.map(boundary::sentence,text.begin(),text.end());
for(p=index.begin(),e=index.end();p!=e;++p) {
wcout<<L"|" <<*p ;
}
wcout<<"|\n\n";
}
#else
int main()
{
std::cout<<"This platform does not support wcout"<<std::endl;
}
#endif