Re: [boost] [regex and string algo] again strange split behaviour

The only reasonable thing is for split to return N+1 pieces for a string with N separators, if you ask me. :-) This is lossless in the sense that it allows you to reconstruct the original string. The non-reasonable behavior can easily be implemented on top of that, but not vice versa.
In fact you can implement the "non-reasonable behavior" on top the "reasonable behavior" with help of boost::sub_match : std::vector<std::string> result; std::string s = "abc/abc/"; boost::regex sep = "/"; boost::sregex_token_iterator tok(s.begin(), s.end(), sep, -1); boost::sregex_token_iterator last; boost::sub_match<boost::sregex_token_iterator> sm; for (; tok != last; ++tok) { sm = *tok; result.push_back(sm); } if (sm.second != s.end()) result.push_back(std::string()); But in the meantime I'm thinking too this should be the default behaviour. Jan
participants (1)
-
Jan Hermelink