Boost logo

Boost Users :

From: David Brownell (david_brownell_at_[hidden])
Date: 2005-01-27 18:38:04


I am attempting to split a string with the string_algo library, using the
code below. It appears that the split algorithm is designed to split on
instances of individual characters rather than sequences of characters. Is
there something I can do to split on a substring? The code below
illustrates the problem, where I am forces to use the is_any_of predicate
rather than something that implies equality. It seems like this is a
trivial use of the algorithm, so there could easily be something that I am
missing.

    typedef std::vector<boost::iterator_range<char const *> >
ResultsType;

    ResultsType results;
    static char const STRING[] = "this\r\nis\r\n\r\na test!";

    boost::split(results,
                 boost::iterator_range<char const *>(STRING, STRING +
sizeof(STRING)),
                 boost::is_any_of("\r\n")); // The problem is here. I
would like to be able
                                             // to use something like
equals, but split requires
                                             // a predicate that takes a
single argument rather than
                                             // a range.

    for(ResultsType::const_iterator rptr = results.begin();
        rptr != results.end();
        ++rptr)
            std::cout << "'" << std::string(rptr->begin(), rptr->end()) <<
"'\n";

Thanks!
David Brownell


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net