There is something about the boost string algorithms that I seem to be missing. I am trying to use a split_iterator with a using Clasifier as the split point. So, for example I would like to be able to do something like this:
make_split_iterator(str, is_space);
however make_split_iterator expects a Range and a Finder. So what I need is to find some sequence to create a Finder from a Classifier. Does anyone know how to do this, or if it is even possible?
You can use token_finder, as in make_split_iterator(str, token_finder(is_space()))
or make_split_iterator(str, token_finder(is_any_of(" ")))
etc.
Full example, assuming your goal is tokenize (hence token_compress_on
)
#include <string>
#include <iostream>
#include <boost/algorithm/string.hpp>
int main()
{
std::string str = "This is a test string";
for( boost::algorithm::split_iterator<std::string::iterator> i
= make_split_iterator(str, token_finder(
boost::algorithm::is_space(),
boost::algorithm::token_compress_on));
i != boost::algorithm::split_iterator<std::string::iterator>();
++i)
{
std::cout << *i << '\n';
}
}
test run: https://ideone.com/vQ2ZM
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With