blob: 9a3c710fa0ae2912378a3d38962f6df610ad9afd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// file : group/driver.cxx
// author : Boris Kolpackov <boris@codesynthesis.com>
// license : MIT; see accompanying LICENSE file
// Test group_scanner.
//
#include <string>
#include <iostream>
#include "test.hxx"
#undef NDEBUG
#include <cassert>
using namespace std;
int
main (int argc, char* argv[])
{
try
{
using namespace cli;
// Mode flags.
//
// 'g' -- don't handle groups.
// 's' -- skip arguments.
//
string m (argv[1]);
bool sa (m.find ('s') != string::npos);
bool sg (m.find ('g') != string::npos);
argv_scanner as (--argc, ++argv);
group_scanner s (as);
// Verify previous two args are still valid for good measure.
//
const char* prev_a (0);
string prev_s;
// Verify position.
//
size_t pos (0); // argv_scanner starts from 1.
while (s.more ())
{
assert (pos < s.position ());
pos = s.position ();
s.peek ();
assert (pos == s.position ());
const char* a (0);
if (!sa)
{
a = s.next ();
cout << "'" << a << "'";
}
else
s.skip ();
if (!sg)
{
scanner& gs (s.group ());
while (gs.more ())
cout << " '" << gs.next () << "'";
}
if (!sa || !sg)
cout << endl;
if (!sa && !sg)
{
s.more ();
if (prev_a != 0)
assert (prev_a == prev_s);
prev_a = a;
prev_s = a;
}
}
return 0;
}
catch (const cli::exception& e)
{
cerr << e << endl;
return 1;
}
}
|