1 /*=============================================================================
2 Copyright (c) 2001-2017 Joel de Guzman
3 Copyright (c) 2017 think-cell GmbH
4
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/spirit/home/qi.hpp>
10 #include <boost/range/adaptor/transformed.hpp>
11
12 #include <iostream>
13 #include <string>
14 #include <functional>
15
16 namespace {
transform_func(char c)17 char transform_func(char c) {
18 return c < 'a' || 'z' < c ? c : static_cast<char>(c - 'a' + 'A');
19 }
20 }
21
main()22 int main()
23 {
24 using boost::adaptors::transform;
25 using boost::spirit::qi::raw;
26 using boost::spirit::qi::eps;
27 using boost::spirit::qi::eoi;
28 using boost::spirit::qi::upper;
29 using boost::spirit::qi::repeat;
30 using boost::spirit::qi::parse;
31
32 std::string input = "abcde";
33 boost::transformed_range<char(*)(char), std::string> const rng = transform(input, transform_func);
34
35 {
36 std::string str;
37 BOOST_TEST((parse(boost::begin(rng), boost::end(rng), +upper >> eoi, str)));
38 BOOST_TEST(("ABCDE"==str));
39 }
40
41 {
42 boost::iterator_range<boost::range_iterator<boost::transformed_range<char(*)(char), std::string> const>::type> str;
43 BOOST_TEST((parse(boost::begin(rng), boost::end(rng), raw[+upper >> eoi], str)));
44 BOOST_TEST((boost::equal(std::string("ABCDE"), str)));
45 }
46
47 {
48 BOOST_TEST((parse(boost::begin(rng), boost::end(rng), (repeat(6)[upper] | repeat(5)[upper]) >> eoi)));
49 }
50
51 return boost::report_errors();
52 }
53