Boost logo

Boost :

From: Jan Hermelink (Jan.Hermelink_at_[hidden])
Date: 2005-07-13 17:06:52


> 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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk