C++ (Qt)#include <iostream>#include <boost/tokenizer.hpp> using namespace boost; template <class CharT>class simple_char_separator{public: typedef std::basic_string<CharT> string_type; typedef typename string_type::const_iterator const_iterator; simple_char_separator() : m_open( "(" ), m_close( ")" ) {} void reset() {} bool operator()( const_iterator &next, const_iterator end, string_type &tok ) const { if( next == end ) return false; const const_iterator start_pos = std::search( next, end, m_open.begin(), m_open.end() ); if( start_pos == end ) return false; const const_iterator end_pos = std::search( start_pos, end, m_close.begin(), m_close.end() ); tok.assign( start_pos, end_pos+1 ); next = ( end_pos == end )? end : end_pos + 1; return true; } private: std::string m_open; std::string m_close;}; int main(){ std::string s = "(10, 20, 30) ( 10, 20, 30 ) (10, 20, 30)"; std::cout << s << std::endl; tokenizer<simple_char_separator<char> > tok( s, simple_char_separator<char>() ); for( auto v : tok ) { std::cout << v << std::endl; } return 0;}
C++ (Qt)tokenizer<simple_char_separator<char> > tok( s, simple_char_separator<char>() );