Using the classifier with split_iterator

There is something about forced string algorithms that I think are missing. I am trying to use split_iterator using Clasifier as the split point. So, for example, I would like to do something like this:

make_split_iterator(str, is_space); 

however make_split_iterator expects Range and Finder. So I need to find some sequence to create a Finder from the classifier. Does anyone know how to do this, or if possible?

+4
source share
1 answer

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.

In general, if 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

+8
source

Source: https://habr.com/ru/post/1345981/


All Articles