]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
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 | =============================================================================*/ | |
11fdf7f2 | 8 | #include <boost/spirit/home/x3.hpp> |
1e59de90 TL |
9 | |
10 | #include <boost/core/lightweight_test.hpp> | |
11fdf7f2 TL |
11 | #include <boost/range/adaptor/transformed.hpp> |
12 | ||
13 | #include <iostream> | |
14 | #include <string> | |
15 | #include <functional> | |
16 | ||
17 | int main() | |
18 | { | |
19 | using boost::adaptors::transform; | |
20 | using boost::spirit::x3::raw; | |
21 | using boost::spirit::x3::eps; | |
22 | using boost::spirit::x3::eoi; | |
23 | using boost::spirit::x3::upper; | |
24 | using boost::spirit::x3::repeat; | |
25 | using boost::spirit::x3::parse; | |
26 | ||
27 | std::string input = "abcde"; | |
28 | std::function<char(char)> func = [](char c) { | |
29 | return c < 'a' || 'z' < c ? c : static_cast<char>(c - 'a' + 'A'); | |
30 | }; | |
31 | auto const rng = transform(input, func); | |
32 | ||
33 | { | |
34 | std::string str; | |
35 | BOOST_TEST((parse(boost::begin(rng), boost::end(rng), +upper >> eoi, str))); | |
36 | BOOST_TEST(("ABCDE"==str)); | |
37 | } | |
38 | ||
39 | { | |
40 | boost::iterator_range<decltype(boost::begin(rng))> str; | |
41 | BOOST_TEST((parse(boost::begin(rng), boost::end(rng), raw[+upper >> eoi], str))); | |
42 | BOOST_TEST((boost::equal(std::string("ABCDE"), str))); | |
43 | } | |
44 | ||
45 | { | |
46 | BOOST_TEST((parse(boost::begin(rng), boost::end(rng), (repeat(6)[upper] | repeat(5)[upper]) >> eoi))); | |
47 | } | |
48 | ||
49 | return boost::report_errors(); | |
50 | } |