| 1 | // Boost.Range library |
| 2 | // |
| 3 | // Copyright Neil Groves 2009. Use, modification and |
| 4 | // distribution is subject to the Boost Software License, Version |
| 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 6 | // http://www.boost.org/LICENSE_1_0.txt) |
| 7 | // |
| 8 | // |
| 9 | // For more information, see http://www.boost.org/libs/range/ |
| 10 | // |
| 11 | //[tokenized_example |
| 12 | #include <boost/range/adaptor/tokenized.hpp> |
| 13 | #include <boost/range/algorithm/copy.hpp> |
| 14 | #include <boost/assign.hpp> |
| 15 | #include <iterator> |
| 16 | #include <iostream> |
| 17 | #include <vector> |
| 18 | |
| 19 | //<- |
| 20 | #include <boost/test/test_tools.hpp> |
| 21 | #include <boost/test/unit_test.hpp> |
| 22 | |
| 23 | #include <boost/range/algorithm_ext/push_back.hpp> |
| 24 | |
| 25 | namespace |
| 26 | { |
| 27 | void tokenized_example_test() |
| 28 | //-> |
| 29 | //=int main(int argc, const char* argv[]) |
| 30 | { |
| 31 | using namespace boost::adaptors; |
| 32 | |
| 33 | typedef boost::sub_match< std::string::iterator > match_type; |
| 34 | |
| 35 | std::string input = " a b c d e f g hijklmnopqrstuvwxyz" ; |
| 36 | boost::copy( |
| 37 | rng: input | tokenized(boost::regex("\\w+" )), |
| 38 | out: std::ostream_iterator<match_type>(std::cout, "\n" )); |
| 39 | |
| 40 | //= return 0; |
| 41 | //=} |
| 42 | //] |
| 43 | using namespace boost::assign; |
| 44 | |
| 45 | std::vector<std::string> reference; |
| 46 | reference += "a" ,"b" ,"c" ,"d" ,"e" ,"f" ,"g" ,"hijklmnopqrstuvwxyz" ; |
| 47 | |
| 48 | std::vector<match_type> test; |
| 49 | boost::push_back(on&: test, from: input | tokenized(boost::regex("\\w+" ))); |
| 50 | |
| 51 | BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), |
| 52 | test.begin(), test.end() ); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | boost::unit_test::test_suite* |
| 57 | init_unit_test_suite(int argc, char* argv[]) |
| 58 | { |
| 59 | boost::unit_test::test_suite* test |
| 60 | = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.tokenized_example" ); |
| 61 | |
| 62 | test->add( BOOST_TEST_CASE( &tokenized_example_test ) ); |
| 63 | |
| 64 | return test; |
| 65 | } |
| 66 | |