#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <boost/typeof/typeof.hpp>
#include <boost/assign.hpp>
#include <list>
using namespace boost;
using namespace std;
using namespace boost::assign;
struct is_contains_a
{
bool operator()(const string& x)
{
return contains(x,"a");
}
};
int main( int argc,char **argv)
{
/*分割*/
string str = "Sam,ZeLinDa,us,Li+nk,Zelinda::Mario,L.inui-wudiab";
cout << str << endl;
deque<string> d;
ifind_all(d,str,"zelinDa");
assert(d.size() == 2);
for(BOOST_AUTO(pos,d.begin());pos != d.end();++pos){
cout << "["<< *pos <<"] " ;
}
cout << endl;
list<iterator_range<string::iterator> > ilist;
split(ilist,str,is_any_of(",.:-+"));
for(BOOST_AUTO(pos,ilist.begin());pos != ilist.end();++pos){
cout << "["<< *pos <<"] " ;
}
cout << endl;
ilist.clear();
split(ilist,str,is_any_of(".:-"),token_compress_on); //参数eCompress可以取值为token_compress_on或token_compress_off,如果值为前者,那么两个分隔符被视为一个,若为后者则连续分隔符标记了一个空字符串,默认为后者。
for(BOOST_AUTO(pos,ilist.begin());pos != ilist.end();++pos){
cout << "["<< *pos <<"] " ;
}
cout << endl;
/*合并*/
vector<string> v = list_of("Tony")("Link")("Ton")("join");
cout << join(v,"+") <<endl; //合并
cout << join_if(v,"**",is_contains_a()); //合并
/*查找分割迭代器*/
string str12("Samus||samus||mario|||linik");
typedef find_iterator<string::iterator> string_find_iterator;;
string_find_iterator pos,end;
for(pos = make_find_iterator(str12,first_finder("samus",is_iequal()));pos != end;++pos)
{
cout <<"[" << *pos << "] ";
}
cout << endl;
typedef split_iterator<string::iterator> string_split_iterator;
string_split_iterator p,endp;
for(p = make_split_iterator(str12,first_finder("||",is_equal()));p != endp;++p)
{
cout << "[" << *p << "] ";
}
cout << endl;
return (0);
}
boost——字符串与文本处理string_algo(二)
最新推荐文章于 2023-07-27 11:05:45 发布