modules/up/src/rpsl/rpsl/regexp.cc
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- dup
- dup
- dup
- dup
- dup
- dup
- dup
- dup
1 // $Id: regexp.cc,v 1.2 2001/09/07 11:42:53 shane Exp $
2 //
3 // Copyright (c) 1994 by the University of Southern California
4 // All rights reserved.
5 //
6 // Permission to use, copy, modify, and distribute this software and its
7 // documentation in source and binary forms for lawful non-commercial
8 // purposes and without fee is hereby granted, provided that the above
9 // copyright notice appear in all copies and that both the copyright
10 // notice and this permission notice appear in supporting documentation,
11 // and that any documentation, advertising materials, and other materials
12 // related to such distribution and use acknowledge that the software was
13 // developed by the University of Southern California, Information
14 // Sciences Institute. The name of the USC may not be used to endorse or
15 // promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THE UNIVERSITY OF SOUTHERN CALIFORNIA DOES NOT MAKE ANY
19 // REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY
20 // PURPOSE. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
21 // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
23 // TITLE, AND NON-INFRINGEMENT.
24 //
25 // IN NO EVENT SHALL USC, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
26 // SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT, TORT,
27 // OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH, THE USE
28 // OR PERFORMANCE OF THIS SOFTWARE.
29 //
30 // Questions concerning this software should be directed to
31 // ratoolset@isi.edu.
32 //
33 // Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU>
34
35 #include "config.h"
36
37 #include "regexp.hh"
38 #include <cstring>
39 #include "symbols.hh"
40
41 // Static members
42 int regexp_symbol::MIN_AS = 0;
43 int regexp_symbol::MAX_AS = RANGE_TOP;
44
45 ////////////////////////////// output ////////////////////
46
47 ostream& operator<<(ostream& os, regexp_symbol& rs) {
48 static RangeList::Range zero_to_zero(0, 0);
49
50 int put_brackets = 0;
51
52 if (rs.asSets.empty() && ! rs.asnumbers.universal()
53 && rs.asnumbers.contains(zero_to_zero)) {
54 rs.complemented = ! rs.complemented;
55 rs.asnumbers.complement();
56 }
57
58 if (rs.complemented
59 || ! ((rs.asnumbers.is_singleton() && rs.asSets.length() == 0)
60 || (rs.asnumbers.empty() && rs.asSets.length() == 1))) {
61 put_brackets = 1;
62 os << "[";
63 if (rs.complemented)
64 os << "^";
65 }
66
67 if (!rs.asnumbers.empty() || rs.asSets.empty())
68 os << rs.asnumbers;
69
70 for (Pix p = rs.asSets.first(); p; rs.asSets.next(p))
71 os << " " << rs.asSets(p);
72
73 if (put_brackets)
74 os << "]";
75
76 return os;
77 }
78
79 ostream& operator<<(ostream& os, const regexp& r) {
80 if (typeid(r) == typeid(regexp_bol))
81 os << "^";
82 else if (typeid(r) == typeid(regexp_eol))
83 os << "$";
84 else if (typeid(r) == typeid(regexp_symbol))
85 os << (regexp_symbol &) r;
86 else if (typeid(r) == typeid(regexp_cat))
87 os << *((regexp_cat &) r).left << " " << *((regexp_cat &) r).right;
88 else if (typeid(r) == typeid(regexp_or))
89 os << "(" << *((regexp_or &) r).left
90 << " | " << *((regexp_or &) r).right << ")";
91 else if (typeid(r) == typeid(regexp_star))
92 if (typeid(((regexp_star &) r).left) == typeid(regexp_cat))
93 os << "(" << *((regexp_star &) r).left << ")*";
94 else
95 os << *((regexp_star &) r).left << "*";
96 else if (typeid(r) == typeid(regexp_question))
97 if (typeid(((regexp_question &) r).left) == typeid(regexp_cat))
98 os << "(" << *((regexp_question &) r).left << ")?";
99 else
100 os << *((regexp_question &) r).left << "?";
101 else if (typeid(r) == typeid(regexp_plus))
102 if (typeid(((regexp_plus &) r).left) == typeid(regexp_cat))
103 os << "(" << *((regexp_plus &) r).left << ")+";
104 else
105 os << *((regexp_plus &) r).left << "+";
106 else
107 os << "REGEXP_UNKNOWN";
108
109 return os;
110 }
111
112 ////////////////////////////// virtual dup ////////////////////
113
114 regexp* regexp_bol::dup() const {
/* [<][>][^][v][top][bottom][index][help] */
115 return new regexp_bol;
116 }
117
118 regexp* regexp_eol::dup() const {
/* [<][>][^][v][top][bottom][index][help] */
119 return new regexp_eol;
120 }
121
122 regexp* regexp_symbol::dup() const {
/* [<][>][^][v][top][bottom][index][help] */
123 return new regexp_symbol((regexp_symbol&) *this);
124 }
125
126 regexp* regexp_cat::dup() const {
/* [<][>][^][v][top][bottom][index][help] */
127 return new regexp_cat(*this);
128 }
129
130 regexp* regexp_or::dup() const {
/* [<][>][^][v][top][bottom][index][help] */
131 return new regexp_or(*this);
132 }
133
134 regexp* regexp_star::dup() const {
/* [<][>][^][v][top][bottom][index][help] */
135 return new regexp_star(*this);
136 }
137
138 regexp* regexp_question::dup() const {
/* [<][>][^][v][top][bottom][index][help] */
139 return new regexp_question(*this);
140 }
141
142 regexp* regexp_plus::dup() const {
/* [<][>][^][v][top][bottom][index][help] */
143 return new regexp_plus(*this);
144 }