]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 1998-2003 Joel de Guzman | |
3 | http://spirit.sourceforge.net/ | |
4 | ||
5 | Use, modification and distribution is subject to the Boost Software | |
6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
7 | http://www.boost.org/LICENSE_1_0.txt) | |
8 | =============================================================================*/ | |
9 | #include <iostream> | |
7c673cae FG |
10 | #include <list> |
11 | ||
12 | ||
13 | #include <boost/spirit/include/classic_core.hpp> | |
14 | #include "impl/string_length.hpp" | |
1e59de90 TL |
15 | |
16 | #include <boost/core/lightweight_test.hpp> | |
17 | ||
7c673cae FG |
18 | using namespace BOOST_SPIRIT_CLASSIC_NS; |
19 | ||
20 | /////////////////////////////////////////////////////////////////////////////// | |
21 | // | |
22 | // Scanner tests | |
23 | // | |
24 | /////////////////////////////////////////////////////////////////////////////// | |
25 | struct to_upper_iter_policy : public iteration_policy { | |
26 | ||
27 | char filter(char ch) const | |
11fdf7f2 | 28 | { using namespace std; return char(toupper(ch)); } |
7c673cae FG |
29 | }; |
30 | ||
31 | inline bool test_isspace(char c) | |
32 | { | |
33 | using namespace std; return isspace(c) != 0; | |
34 | } | |
35 | ||
36 | inline bool test_islower(char c) | |
37 | { | |
38 | using namespace std; return islower(c) != 0; | |
39 | } | |
40 | ||
41 | struct skip_white_iter_policy : public iteration_policy { | |
42 | ||
43 | template <typename ScannerT> | |
44 | void | |
45 | advance(ScannerT const& scan) const | |
46 | { | |
47 | do | |
48 | ++scan.first; | |
49 | while (!at_end(scan) && test_isspace(get(scan))); | |
50 | } | |
51 | }; | |
52 | ||
53 | void | |
54 | scanner_tests() | |
55 | { | |
56 | char const* cp = "The Big Brown Fox Jumped \n\tOver The Lazy Dog's Back"; | |
57 | char const* cp_first = cp; | |
58 | char const* cp_last = cp + test_impl::string_length(cp); | |
59 | ||
60 | scanner<char const*> | |
61 | pp1(cp_first, cp_last); | |
62 | ||
63 | // compile check only... | |
64 | scanner<> spp1(pp1); (void)spp1; | |
65 | scanner<> spp2(pp1); (void)spp2; | |
66 | // spp1 = spp2; | |
67 | // compile check only... | |
68 | ||
69 | while (!pp1.at_end()) | |
70 | { | |
71 | std::cout << *pp1; | |
72 | ++pp1; | |
73 | } | |
74 | std::cout << '\n'; | |
75 | cp_first = cp; | |
76 | ||
77 | std::list<char> li(cp_first, cp_last); | |
78 | std::list<char>::iterator li_first = li.begin(); | |
79 | std::list<char>::iterator li_last = li.end(); | |
80 | ||
81 | scanner<std::list<char>::iterator> | |
82 | pp2(li_first, li_last); | |
83 | ||
84 | while (!pp2.at_end()) | |
85 | { | |
86 | std::cout << *pp2; | |
87 | ++pp2; | |
88 | } | |
89 | std::cout << '\n'; | |
90 | li_first = li.begin(); | |
91 | ||
92 | scanner<char const*, scanner_policies<to_upper_iter_policy> > | |
93 | pp3(cp_first, cp_last); | |
94 | ||
95 | while (!pp3.at_end()) | |
96 | { | |
97 | std::cout << *pp3; | |
98 | BOOST_TEST(!test_islower(*pp3)); | |
99 | ++pp3; | |
100 | } | |
101 | std::cout << '\n'; | |
102 | cp_first = cp; | |
103 | ||
104 | scanner<char const*, scanner_policies<skip_white_iter_policy> > | |
105 | pp4(cp_first, cp_last); | |
106 | ||
107 | // compile check only... | |
108 | pp1.change_policies(scanner_policies<skip_white_iter_policy>()); | |
109 | // compile check only... | |
110 | ||
111 | while (!pp4.at_end()) | |
112 | { | |
113 | std::cout << *pp4; | |
114 | BOOST_TEST(!test_isspace(*pp4)); | |
115 | ++pp4; | |
116 | } | |
117 | std::cout << '\n'; | |
118 | cp_first = cp; | |
119 | ||
120 | std::cout << "sizeof(scanner<>) == " << sizeof(scanner<>) << '\n'; | |
121 | ||
122 | parse_info<> pi = parse("12abcdefg12345ABCDEFG789", +digit_p, alpha_p); | |
123 | BOOST_TEST(pi.hit); | |
124 | BOOST_TEST(pi.full); | |
125 | ||
126 | pi = parse("abcdefg12345ABCDEFG789", +digit_p, alpha_p); | |
127 | BOOST_TEST(pi.hit); | |
128 | BOOST_TEST(pi.full); | |
129 | } | |
130 | ||
131 | /////////////////////////////////////////////////////////////////////////////// | |
132 | // | |
133 | // Main | |
134 | // | |
135 | /////////////////////////////////////////////////////////////////////////////// | |
136 | int | |
137 | main() | |
138 | { | |
139 | scanner_tests(); | |
140 | return boost::report_errors(); | |
141 | } | |
142 |