File: driver.cc

package info (click to toggle)
bobcat 4.08.06-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,212 kB
  • sloc: cpp: 16,118; fortran: 4,959; makefile: 3,723; sh: 535; perl: 401; ansic: 26
file content (130 lines) | stat: -rw-r--r-- 3,252 bytes parent folder | download
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
                              driver.cc
*/

#include "driver.h"

//#include <bobcat/pattern>
#include "../pattern.ih"

using namespace std;
using namespace FBB;

#include <algorithm>
#include <cstring>

void Pattern::swap(Pattern &other)
{
    fswap(*this, other);
    fswap(d_text, other.d_text);
    d_text.swap(other.d_text);
}


void showSubstr(string const &str)
{
    static int 
        count = 1;

    cout << "String " << count++ << " is '" << str << "'\n";
}


int main(int argc, char **argv)
{
//    {
//        Pattern one("one");
////        Pattern two(one);
//        Pattern three("a");
//        Pattern four;
//        three = three;
//    }


//    try 
//    {
//        Pattern pattern("aap|noot|mies");
//
//        {
//            Pattern extra(Pattern(pattern));
//        }
//    
//        if (pattern << "noot")
//            cout << "noot matches\n";
//        else
//            cout << ": noot doesn't match\n";
//    }
//    catch (exception const &e)
//    {
//        cout << e.what() << ": compilation failed" << endl;
//    }
//        
    string pat = "\\d+";

    while (true)
    {
        cout << "Pattern: '" << pat << "'\n";

        try
        {
            Pattern patt(pat, argc == 1);   // case sensitive by default,
                                            // any arg for case insensitive

            cout << "Compiled pattern: " << patt.pattern() << endl;

            Pattern pattern;
            pattern = patt;                 // assignment operator

            while (true)
            {
                cout << "string to match : ";

                string st;
                getline(cin, st);
                if (st == "")
                    break;
                cout << "String: '" << st << "'\n";
                try
                {
                    pattern.match(st);

                    Pattern p3(pattern);
        
                    cout << "before:  " << p3.before() << "\n"
                            "matched: " << p3.matched() << "\n"  
                            "beyond:  " << pattern.beyond() << "\n"  
                            "end() = " << pattern.end() << endl;
        
                    for (size_t idx = 0; idx < pattern.end(); ++idx)
                    {
                        string str = pattern[idx];
            
                        if (str == "")
                            cout << "part " << idx << " not present\n";
                        else
                        {
                            Pattern::Position pos = pattern.position(idx);
        
                            cout << "part " << idx << ": '" << str << "' (" <<
                                    pos.first << "-" << pos.second << ")\n";
                        }
                    }
                }
                catch (exception const &e)
                {
                    cout << e.what() << ": " << st << " doesn't match" << endl;
                    continue;
                }
            }
        }            
        catch (exception const &e)
        {
            cout << e.what() << ": compilation failed" << endl;
        }

        cout << "New pattern: ";

        if (!getline(cin, pat) || !pat.length())
            return 0;
    }
}