regxstring_impl.cpp

filter: Statementstmt 73.2% 494 / 674 Branchbran 43.7% 295 / 674 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 58.5% 789 / 1348 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« regxstring.cpp ↑ Summary harness.cpp »
1 #include <algorithm>
2 #include <sstream>
3 #include <ctime>
4 #include <cassert>
5 #include "regxstring.h"
6 #include "regxstring_impl.h"
7  
8 #if _DZ_DEBUG
9 # include <iostream>
10  
11 static void printRefs(__DZ_OSTRINGSTREAM & oss,const REGXSTRING_NS::__Refs & refs)
12 {
13 for(REGXSTRING_NS::__Refs::const_iterator i = refs.begin();i != refs.end();++i)
14 std::cout<<"\t"<<oss.str().substr(i->first,i->second);
15 }
16  
17 # define _OSS_OUT(msg) { \
18 std::cout<<msg<<" : "<<gdata.oss_.str(); \
19 printRefs(gdata.oss_,gdata.refs_); \
20 std::cout<<std::endl;}
21  
22 #else
23 # define _OSS_OUT(str)
24 #endif
25  
26 NAMESAPCE_BEGIN
27  
28 // Replacements for new and delete
29 template<class T>
30 98 T * New(){
31 98 ▶ T * ret = __DZ_ALLOC<T>().allocate(1);
Branch: 1 branch
BranchTrueFalseTotal
T * ret = __DZ_ALLOC<T>().allocate(1); 98 0 98
32 98 ▶ return new (ret) T;
Branch: 2 branches
BranchTrueFalseTotal
return new (ret) T; 98 0 98
return new (ret) T; 0 0 0
33 }
34  
35 template<class T,class A>
36 0 T * New(const A & a){
37 0 ▶ T * ret = __DZ_ALLOC<T>().allocate(1);
Branch: 6 branches
BranchTrueFalseTotal
T * ret = __DZ_ALLOC<T>().allocate(1); 13 0 13
T * ret = __DZ_ALLOC<T>().allocate(1); 0 0 0
T * ret = __DZ_ALLOC<T>().allocate(1); 0 0 0
T * ret = __DZ_ALLOC<T>().allocate(1); 1143 0 1143
T * ret = __DZ_ALLOC<T>().allocate(1); 362 0 362
T * ret = __DZ_ALLOC<T>().allocate(1); 560 0 560
38 0 ▶ return new (ret) T(a);
Branch: 12 branches
BranchTrueFalseTotal
return new (ret) T(a); 13 0 13
return new (ret) T(a); 0 0 0
return new (ret) T(a); 0 0 0
return new (ret) T(a); 0 0 0
return new (ret) T(a); 0 0 0
return new (ret) T(a); 0 0 0
return new (ret) T(a); 1143 0 1143
return new (ret) T(a); 0 0 0
return new (ret) T(a); 362 0 362
return new (ret) T(a); 0 0 0
return new (ret) T(a); 560 0 560
return new (ret) T(a); 0 0 0
39 }
40  
41 template<class T,class A,class B>
42 0 T * New(const A & a,const B & b){
43 0 ▶ T * ret = __DZ_ALLOC<T>().allocate(1);
Branch: 5 branches
BranchTrueFalseTotal
T * ret = __DZ_ALLOC<T>().allocate(1); 362 0 362
T * ret = __DZ_ALLOC<T>().allocate(1); 0 0 0
T * ret = __DZ_ALLOC<T>().allocate(1); 202 0 202
T * ret = __DZ_ALLOC<T>().allocate(1); 0 0 0
T * ret = __DZ_ALLOC<T>().allocate(1); 13 0 13
44 0 ▶ return new (ret) T(a,b);
Branch: 13 branches
BranchTrueFalseTotal
return new (ret) T(a,b); 362 0 362
return new (ret) T(a,b); 0 0 0
return new (ret) T(a,b); 0 0 0
return new (ret) T(a,b); 0 0 0
return new (ret) T(a,b); 0 0 0
return new (ret) T(a,b); 202 0 202
return new (ret) T(a,b); 202 0 202
return new (ret) T(a,b); 0 0 0
return new (ret) T(a,b); 0 0 0
return new (ret) T(a,b); 0 0 0
return new (ret) T(a,b); 0 0 0
return new (ret) T(a,b); 13 0 13
return new (ret) T(a,b); 0 0 0
45 }
46  
47 template<class T,class A,class B,class C>
48 199 T * New(const A & a,const B & b,const C & c){
49 199 ▶ T * ret = __DZ_ALLOC<T>().allocate(1);
Branch: 1 branch
BranchTrueFalseTotal
T * ret = __DZ_ALLOC<T>().allocate(1); 199 0 199
50 199 ▶ return new (ret) T(a,b,c);
Branch: 2 branches
BranchTrueFalseTotal
return new (ret) T(a,b,c); 199 0 199
return new (ret) T(a,b,c); 0 0 0
51 }
52 template<class T>
53 0 void Delete(T * p){
54 typedef char __dummy[sizeof(T)];
55 0 ▶ if(p){
Branch: 2 branches
BranchTrueFalseTotal
if(p){ 0 0 0
if(p){ 2952 0 2952
56 0 p->~T();
57 0 __DZ_ALLOC<T>().deallocate(p,1);
58 }
59 0 }
60  
61 struct __IsNull
62 {
63 1275 bool operator ()(__NodeBase * n) const{
64 1275 return !n;
65 }
66 };
67  
68 static const char * const SEP = " ";
69  
70 1353 static __DZ_STRING sep(int lvl)
71 {
72 1353 __DZ_STRING ret;
73 3897 ▶ while(lvl-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while(lvl-- > 0) 2544 1353 3897
74 2544 ▶ ret += SEP;
Branch: 1 branch
BranchTrueFalseTotal
ret += SEP; 2544 0 2544
75 1353 return ret;
76 }
77  
78 2546 static void appendNode(__NodeBase *& parent,__NodeBase * node)
79 {
80 2546 ▶ if(!node)
Branch: 1 branch
BranchTrueFalseTotal
if(!node) 379 2167 2546
81 379 return;
82 2167 ▶ if(!parent)
Branch: 1 branch
BranchTrueFalseTotal
if(!parent) 560 1607 2167
83 560 parent = New<__Seq>(node);
84 else
85 1607 parent->AppendNode(node);
86 }
87  
88 namespace Tools{
89  
90 2577 inline bool IsRepeat(int ch){
91 2577 ▶ return ch == '?' || ch == '+' || ch == '*';
Branch: 3 branches
BranchTrueFalseTotal
return ch == '?' || ch == '+' || ch == '*'; 2564 13 2577
return ch == '?' || ch == '+' || ch == '*'; 2564 0 2564
return ch == '?' || ch == '+' || ch == '*'; 0 2564 2564
92 }
93  
94 1139 inline bool IsBegin(int ch){
95 1139 return ch == '^';
96 }
97  
98 1986 inline bool IsEnd(int ch){
99 1986 return ch == '$';
100 }
101  
102 1527 inline bool IsSlash(int ch){
103 1527 return ch == '\\';
104 }
105  
106 1805 inline bool IsSetBegin(int ch){
107 1805 return ch == '[';
108 }
109  
110 280 inline bool IsSetEnd(int ch){
111 280 return ch == ']';
112 }
113  
114 1707 inline bool IsGroupBegin(int ch){
115 1707 return ch == '(';
116 }
117  
118 1474 inline bool IsGroupEnd(int ch){
119 1474 return ch == ')';
120 }
121  
122 1999 inline bool IsSelect(int ch){
123 1999 return ch == '|';
124 }
125  
126 2564 inline bool IsRepeatBegin(int ch){
127 2564 return ch == '{';
128 }
129  
130 46 inline bool IsRepeatEnd(int ch){
131 46 return ch == '}';
132 }
133  
134 1474 inline bool NeedEnd(int ch){
135 1474 ▶ return IsGroupEnd(ch) || IsRepeatEnd(ch);
Branch: 2 branches
BranchTrueFalseTotal
return IsGroupEnd(ch) || IsRepeatEnd(ch); 46 1428 1474
return IsGroupEnd(ch) || IsRepeatEnd(ch); 0 46 46
136 }
137  
138 475 inline bool IsDigit(int ch){
139 475 ▶ return '0' <= ch && ch <= '9';
Branch: 2 branches
BranchTrueFalseTotal
return '0' <= ch && ch <= '9'; 463 12 475
return '0' <= ch && ch <= '9'; 264 199 463
140 }
141  
142 264 inline int TransDigit(int ch){
143 264 return ch - '0';
144 }
145  
146 398 inline bool IsDash(int ch){
147 398 return ch == '-';
148 }
149  
150 1805 inline bool IsAny(int ch){
151 1805 return ch == '.';
152 }
153  
154 362 inline int IsSubexpMark(int ch){
155 362 ▶ return (ch == ':' || ch == '=' || ch == '!' || ch == '>' ? ch : 0);
Branch: 4 branches
BranchTrueFalseTotal
return (ch == ':' || ch == '=' || ch == '!' || ch == '>' ? ch : 0); 362 0 362
return (ch == ':' || ch == '=' || ch == '!' || ch == '>' ? ch : 0); 362 0 362
return (ch == ':' || ch == '=' || ch == '!' || ch == '>' ? ch : 0); 362 0 362
return (ch == ':' || ch == '=' || ch == '!' || ch == '>' ? ch : 0); 0 362 362
156 }
157  
158 362 inline int IsSubexpMark(const char * s){
159 362 ▶ return (*s == '?' ? IsSubexpMark(*(s + 1)) : 0);
Branch: 1 branch
BranchTrueFalseTotal
return (*s == '?' ? IsSubexpMark(*(s + 1)) : 0); 0 362 362
160 }
161  
162 210 inline char TransSlash(int ch){
163 210 switch(ch){
164 0 case 'f':return '\f';
165 0 case 'n':return '\n';
166 0 case 'r':return '\r';
167 0 case 't':return '\t';
168 0 case 'v':return '\v';
169 }
170 210 return ch;
171 }
172 }
173  
174 //struct __ParseData
175 2365 int __ParseData::inEnds(int ch) const
176 {
177 2365 int ret = 1;
178 2411 ▶ for(__Ends::const_reverse_iterator i = ends_.rbegin();i != ends_.rend();++i,++ret){
Branch: 2 branches
BranchTrueFalseTotal
for(__Ends::const_reverse_iterator i = ends_.rbegin();i != ends_.rend();++i,++ret){ 2411 0 2411
for(__Ends::const_reverse_iterator i = ends_.rbegin();i != ends_.rend();++i,++ret){ 1840 571 2411
179 1840 ▶ if(ch == *i)
Branch: 1 branch
BranchTrueFalseTotal
if(ch == *i) 366 1474 1840
180 366 return ret;
181 1474 ▶ if(Tools::NeedEnd(*i))
Branch: 1 branch
BranchTrueFalseTotal
if(Tools::NeedEnd(*i)) 1428 46 1474
182 1428 break;
183 }
184 1999 return 0;
185 }
186  
187 //struct __NodeBase
188 __NodeBase * const __NodeBase::REP_NULL = (__NodeBase *)1;
189  
190 #if _MEM_LEAK
191 int __NodeBase::ref = 0;
192 #endif
193  
194 0 __NodeBase::~__NodeBase()
195 {
196 #if _MEM_LEAK
197 --ref;
198 #endif
199 0 }
200  
201 212 int __NodeBase::Repeat(int ch)
202 {
203 212 return 1;
204 }
205  
206 0 void __NodeBase::AppendNode(__NodeBase * node)
207 {
208 0 assert(0);
209 }
210  
211 //struct __Edge
212 362 __Edge::__Edge(int ch)
213 362 : begin_(ch == '^')
214 362 {}
215  
216 362 __NodeBase * __Edge::Optimize(__ParseData & pdata)
217 {
218 362 return REP_NULL;
219 }
220  
221 0 void __Edge::RandString(__GenerateData & gdata) const
222 {
223 _OSS_OUT("__Edge");
224 0 }
225  
226 0 void __Edge::Debug(std::ostream & out,int lvl) const
227 {
228 0 ▶ out<<sep(lvl)<<(begin_ ? "BEGIN" : "END")<<"\n";
Branch: 5 branches
BranchTrueFalseTotal
out<<sep(lvl)<<(begin_ ? "BEGIN" : "END")<<"\n"; 0 0 0
out<<sep(lvl)<<(begin_ ? "BEGIN" : "END")<<"\n"; 0 0 0
out<<sep(lvl)<<(begin_ ? "BEGIN" : "END")<<"\n"; 0 0 0
out<<sep(lvl)<<(begin_ ? "BEGIN" : "END")<<"\n"; 0 0 0
out<<sep(lvl)<<(begin_ ? "BEGIN" : "END")<<"\n"; 0 0 0
229 0 }
230  
231 //struct __Text
232 1143 __Text::__Text(int ch)
233 2286 ▶ : str_(1,ch)
Branch: 1 branch
BranchTrueFalseTotal
: str_(1,ch) 1143 0 1143
234 1143 {}
235  
236 221 __NodeBase * __Text::Optimize(__ParseData & pdata)
237 {
238 221 ▶ return (str_.empty() ? REP_NULL : 0);
Branch: 1 branch
BranchTrueFalseTotal
return (str_.empty() ? REP_NULL : 0); 0 221 221
239 }
240  
241 20439 void __Text::RandString(__GenerateData & gdata) const
242 {
243 20439 gdata.oss_<<str_;
244 _OSS_OUT("__Text");
245 20439 }
246  
247 217 void __Text::Debug(std::ostream & out,int lvl) const
248 {
249 217 ▶ out<<sep(lvl)<<"Text("<<str_<<")\n";
Branch: 5 branches
BranchTrueFalseTotal
out<<sep(lvl)<<"Text("<<str_<<")\n"; 217 0 217
out<<sep(lvl)<<"Text("<<str_<<")\n"; 217 0 217
out<<sep(lvl)<<"Text("<<str_<<")\n"; 217 0 217
out<<sep(lvl)<<"Text("<<str_<<")\n"; 217 0 217
out<<sep(lvl)<<"Text("<<str_<<")\n"; 217 0 217
250 217 }
251  
252 //class __Charset
253 98 __Charset::__Charset()
254 98 : inc_(1)
255 98 {}
256  
257 202 __Charset::__Charset(const __DZ_STRING & str,bool include)
258 202 : str_(str)
259 202 ▶ , inc_(include)
Branch: 1 branch
BranchTrueFalseTotal
, inc_(include) 202 0 202
260 202 {}
261  
262 300 __NodeBase * __Charset::Optimize(__ParseData & pdata)
263 {
264 300 ▶ if(!inc_)
Branch: 1 branch
BranchTrueFalseTotal
if(!inc_) 0 300 300
265 0 reverse();
266 300 ▶ if(str_.empty())
Branch: 1 branch
BranchTrueFalseTotal
if(str_.empty()) 0 300 300
267 0 return REP_NULL;
268 300 inc_ = str_.size();
269 300 return 0;
270 }
271  
272 159051 void __Charset::RandString(__GenerateData & gdata) const
273 {
274 159051 ▶ assert(inc_ == str_.size());
Branch: 1 branch
BranchTrueFalseTotal
assert(inc_ == str_.size()); 0 159051 159051
275 159051 gdata.oss_<<str_[rand() % inc_];
276 _OSS_OUT("__Charset");
277 159051 }
278  
279 296 void __Charset::Debug(std::ostream & out,int lvl) const
280 {
281 592 ▶ out<<sep(lvl)<<"Charset(INCLUDE"
Branch: 1 branch
BranchTrueFalseTotal
out<<sep(lvl)<<"Charset(INCLUDE" 296 0 296
282 296 ▶ <<", "<<str_<<")\n";
Branch: 5 branches
BranchTrueFalseTotal
<<", "<<str_<<")\n"; 296 0 296
<<", "<<str_<<")\n"; 296 0 296
<<", "<<str_<<")\n"; 296 0 296
<<", "<<str_<<")\n"; 296 0 296
<<", "<<str_<<")\n"; 296 0 296
283 296 }
284  
285 0 void __Charset::Exclude()
286 {
287 0 inc_ = 0;
288 0 }
289  
290 64 void __Charset::AddChar(int ch)
291 {
292 64 str_.push_back(ch);
293 64 }
294  
295 118 void __Charset::AddRange(int from,int to)
296 {
297 1606 ▶ for(;from <= to;++from)
Branch: 1 branch
BranchTrueFalseTotal
for(;from <= to;++from) 1488 118 1606
298 1488 str_.push_back(from);
299 118 }
300  
301 0 void __Charset::AddRange(__Charset * node)
302 {
303 0 ▶ if(!node)
Branch: 1 branch
BranchTrueFalseTotal
if(!node) 0 0 0
304 0 return;
305 0 unite(*node);
306 }
307  
308 300 void __Charset::Unique()
309 {
310 300 ▶ inc_ ? unique() : reverse();
Branch: 1 branch
BranchTrueFalseTotal
inc_ ? unique() : reverse(); 300 0 300
311 300 }
312  
313 0 void __Charset::unite(__Charset & node)
314 {
315 0 ▶ if(!node.inc_)
Branch: 1 branch
BranchTrueFalseTotal
if(!node.inc_) 0 0 0
316 0 node.reverse();
317 0 str_ += node.str_;
318 0 }
319  
320 0 void __Charset::reverse()
321 {
322 0 const int _CHAR_MIN = 32;
323 0 const int _CHAR_MAX = 126;
324 0 ▶ unique();
Branch: 1 branch
BranchTrueFalseTotal
unique(); 0 0 0
325 0 __DZ_STRING s;
326 0 s.swap(str_);
327 0 int c = _CHAR_MIN;
328 0 size_t i = 0,e = s.size();
329 0 ▶ for(;c <= _CHAR_MAX && i < e;++i){
Branch: 2 branches
BranchTrueFalseTotal
for(;c <= _CHAR_MAX && i < e;++i){ 0 0 0
for(;c <= _CHAR_MAX && i < e;++i){ 0 0 0
330 0 ▶ int ch = s[i];
Branch: 1 branch
BranchTrueFalseTotal
int ch = s[i]; 0 0 0
331 0 ▶ if(c < ch)
Branch: 1 branch
BranchTrueFalseTotal
if(c < ch) 0 0 0
332 0 ▶ AddRange(c,ch - 1);
Branch: 1 branch
BranchTrueFalseTotal
AddRange(c,ch - 1); 0 0 0
333 0 c = std::max(ch + 1,_CHAR_MIN);
334 }
335 0 ▶ if(c <= _CHAR_MAX)
Branch: 1 branch
BranchTrueFalseTotal
if(c <= _CHAR_MAX) 0 0 0
336 0 ▶ AddRange(c,_CHAR_MAX);
Branch: 1 branch
BranchTrueFalseTotal
AddRange(c,_CHAR_MAX); 0 0 0
337 0 inc_ = !inc_;
338 0 }
339  
340 300 void __Charset::unique()
341 {
342 300 ▶ if(!str_.empty()){
Branch: 1 branch
BranchTrueFalseTotal
if(!str_.empty()){ 300 0 300
343 300 std::sort(str_.begin(),str_.end());
344 300 ▶ str_.erase(std::unique(str_.begin(),str_.end()),str_.end());
Branch: 2 branches
BranchTrueFalseTotal
str_.erase(std::unique(str_.begin(),str_.end()),str_.end()); 300 0 300
str_.erase(std::unique(str_.begin(),str_.end()),str_.end()); 300 0 300
345 }
346 300 }
347  
348 //class __Repeat
349 13 __Repeat::__Repeat(__NodeBase * node,int ch)
350 13 : node_(node)
351 13 , min_(0)
352 13 , max_(0)
353 {
354 13 switch(ch){
355 13 case '?':min_ = 0;max_ = 1;break;
356 0 case '+':min_ = 1;max_ = INFINITE;break;
357 0 case '*':min_ = 0;max_ = INFINITE;break;
358 13 default:;
359 }
360 13 }
361  
362 199 __Repeat::__Repeat(__NodeBase * node,int min,int max)
363 199 : node_(node)
364 199 , min_(min)
365 199 , max_(max)
366 199 {}
367  
368 0 __Repeat::~__Repeat(){
369 212 Delete(node_);
370 0 }
371  
372 212 __NodeBase * __Repeat::Optimize(__ParseData & pdata)
373 {
374 212 min_ &= _CLEAR_FLAGS;
375 212 max_ &= _CLEAR_FLAGS;
376 212 ▶ if(isInfinite()){
Branch: 1 branch
BranchTrueFalseTotal
if(isInfinite()){ 0 212 212
377 0 max_ = min_ + pdata.config_.repeatInfinite;
378 0 ▶ if( max_ > _REPEAT_MAX)
Branch: 1 branch
BranchTrueFalseTotal
if( max_ > _REPEAT_MAX) 0 0 0
379 0 max_ = _REPEAT_MAX;
380 }
381 212 ▶ if(!node_ || (min_ > max_) || (!min_ && !max_))
Branch: 4 branches
BranchTrueFalseTotal
if(!node_ || (min_ > max_) || (!min_ && !max_)) 212 0 212
if(!node_ || (min_ > max_) || (!min_ && !max_)) 212 0 212
if(!node_ || (min_ > max_) || (!min_ && !max_)) 13 199 212
if(!node_ || (min_ > max_) || (!min_ && !max_)) 0 13 13
382 0 return REP_NULL;
383 212 __NodeBase * r = node_->Optimize(pdata);
384 212 ▶ if(r == REP_NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(r == REP_NULL) 0 212 212
385 0 return REP_NULL;
386 212 ▶ else if(r){
Branch: 1 branch
BranchTrueFalseTotal
else if(r){ 0 212 212
387 0 Delete(node_);
388 0 node_ = r;
389 }
390 212 ▶ if(1 == max_ && 1 == min_){
Branch: 2 branches
BranchTrueFalseTotal
if(1 == max_ && 1 == min_){ 13 199 212
if(1 == max_ && 1 == min_){ 0 13 13
391 0 r = node_;
392 0 node_ = 0;
393 0 return r;
394 }
395 212 max_ -= min_ - 1;
396 212 return 0;
397 }
398  
399 19805 void __Repeat::RandString(__GenerateData & gdata) const
400 {
401 169484 ▶ for(int t = min_ + rand() % max_;t > 0;t--)
Branch: 1 branch
BranchTrueFalseTotal
for(int t = min_ + rand() % max_;t > 0;t--) 149679 19805 169484
402 149679 node_->RandString(gdata);
403 _OSS_OUT("__Repeat");
404 19805 }
405  
406 208 void __Repeat::Debug(std::ostream & out,int lvl) const
407 {
408 208 ▶ out<<sep(lvl)<<"Repeat["<<min_<<", "<<(min_ + max_ - 1)<<"]\n";
Branch: 7 branches
BranchTrueFalseTotal
out<<sep(lvl)<<"Repeat["<<min_<<", "<<(min_ + max_ - 1)<<"]\n"; 208 0 208
out<<sep(lvl)<<"Repeat["<<min_<<", "<<(min_ + max_ - 1)<<"]\n"; 208 0 208
out<<sep(lvl)<<"Repeat["<<min_<<", "<<(min_ + max_ - 1)<<"]\n"; 208 0 208
out<<sep(lvl)<<"Repeat["<<min_<<", "<<(min_ + max_ - 1)<<"]\n"; 208 0 208
out<<sep(lvl)<<"Repeat["<<min_<<", "<<(min_ + max_ - 1)<<"]\n"; 208 0 208
out<<sep(lvl)<<"Repeat["<<min_<<", "<<(min_ + max_ - 1)<<"]\n"; 208 0 208
out<<sep(lvl)<<"Repeat["<<min_<<", "<<(min_ + max_ - 1)<<"]\n"; 208 0 208
409 208 ++lvl;
410 208 ▶ if(node_)
Branch: 1 branch
BranchTrueFalseTotal
if(node_) 208 0 208
411 208 node_->Debug(out,lvl);
412 else
413 0 ▶ out<<sep(lvl)<<"NULL\n";
Branch: 3 branches
BranchTrueFalseTotal
out<<sep(lvl)<<"NULL\n"; 0 0 0
out<<sep(lvl)<<"NULL\n"; 0 0 0
out<<sep(lvl)<<"NULL\n"; 0 0 0
414 208 }
415  
416 0 int __Repeat::Repeat(int ch)
417 {
418 0 ▶ if(canRepeat()){
Branch: 1 branch
BranchTrueFalseTotal
if(canRepeat()){ 0 0 0
419 0 switch(ch){
420 0 case '?':min_ |= _NON_GREEDY;return 2;break;
421 0 case '+':min_ |= _PROSSESSIVE;return 2;break;
422 0 default:;
423 }
424 }
425 0 return 0;
426 }
427  
428 //class __Seq
429 560 __Seq::__Seq(__NodeBase * node)
430 1120 ▶ : seq_(1,node)
Branch: 1 branch
BranchTrueFalseTotal
: seq_(1,node) 560 0 560
431 560 {}
432  
433 0 __Seq::~__Seq(){
434 1144 ▶ for(__Con::const_iterator i = seq_.begin(),e = seq_.end();i != e;++i)
Branch: 1 branch
BranchTrueFalseTotal
for(__Con::const_iterator i = seq_.begin(),e = seq_.end();i != e;++i) 584 560 1144
435 584 Delete(*i);
436 0 }
437  
438 560 __NodeBase * __Seq::Optimize(__ParseData & pdata)
439 {
440 560 ▶ if(seq_.empty())
Branch: 1 branch
BranchTrueFalseTotal
if(seq_.empty()) 0 560 560
441 0 return REP_NULL;
442 1805 ▶ for(__Con::iterator i = seq_.begin(),e = seq_.end();i != e;++i)
Branch: 1 branch
BranchTrueFalseTotal
for(__Con::iterator i = seq_.begin(),e = seq_.end();i != e;++i) 1245 560 1805
443 1245 ▶ if(*i){
Branch: 1 branch
BranchTrueFalseTotal
if(*i){ 1245 0 1245
444 1245 ▶ __NodeBase * r = (*i)->Optimize(pdata);
Branch: 1 branch
BranchTrueFalseTotal
__NodeBase * r = (*i)->Optimize(pdata); 1245 0 1245
445 1245 ▶ if(r){
Branch: 1 branch
BranchTrueFalseTotal
if(r){ 362 883 1245
446 362 ▶ Delete(*i);
Branch: 1 branch
BranchTrueFalseTotal
Delete(*i); 362 0 362
447 362 ▶ *i = (r == REP_NULL ? 0 : r);
Branch: 1 branch
BranchTrueFalseTotal
*i = (r == REP_NULL ? 0 : r); 0 362 362
448 }
449 }
450 560 ▶ seq_.erase(std::remove_if(seq_.begin(),seq_.end(),__IsNull()),seq_.end());
Branch: 2 branches
BranchTrueFalseTotal
seq_.erase(std::remove_if(seq_.begin(),seq_.end(),__IsNull()),seq_.end()); 560 0 560
seq_.erase(std::remove_if(seq_.begin(),seq_.end(),__IsNull()),seq_.end()); 560 0 560
451 560 ▶ if(seq_.empty())
Branch: 1 branch
BranchTrueFalseTotal
if(seq_.empty()) 0 560 560
452 0 return REP_NULL;
453 560 ▶ if(seq_.size() == 1){
Branch: 1 branch
BranchTrueFalseTotal
if(seq_.size() == 1){ 299 261 560
454 299 __NodeBase * r = seq_[0];
455 299 seq_.clear();
456 299 return r;
457 }
458 261 return 0;
459 }
460  
461 26003 void __Seq::RandString(__GenerateData & gdata) const
462 {
463 84015 ▶ for(__Con::const_iterator i = seq_.begin(),e = seq_.end();i != e;++i)
Branch: 1 branch
BranchTrueFalseTotal
for(__Con::const_iterator i = seq_.begin(),e = seq_.end();i != e;++i) 58012 26003 84015
464 58012 ▶ (*i)->RandString(gdata);
Branch: 1 branch
BranchTrueFalseTotal
(*i)->RandString(gdata); 58012 0 58012
465 _OSS_OUT("__Seq");
466 26003 }
467  
468 260 void __Seq::Debug(std::ostream & out,int lvl) const
469 {
470 260 ▶ out<<sep(lvl)<<"Seq("<<seq_.size()<<")\n";
Branch: 5 branches
BranchTrueFalseTotal
out<<sep(lvl)<<"Seq("<<seq_.size()<<")\n"; 260 0 260
out<<sep(lvl)<<"Seq("<<seq_.size()<<")\n"; 260 0 260
out<<sep(lvl)<<"Seq("<<seq_.size()<<")\n"; 260 0 260
out<<sep(lvl)<<"Seq("<<seq_.size()<<")\n"; 260 0 260
out<<sep(lvl)<<"Seq("<<seq_.size()<<")\n"; 260 0 260
471 260 ++lvl;
472 840 ▶ for(__Con::const_iterator i = seq_.begin(),e = seq_.end();i != e;++i){
Branch: 1 branch
BranchTrueFalseTotal
for(__Con::const_iterator i = seq_.begin(),e = seq_.end();i != e;++i){ 580 260 840
473 580 ▶ if(*i)
Branch: 1 branch
BranchTrueFalseTotal
if(*i) 580 0 580
474 580 ▶ (*i)->Debug(out,lvl);
Branch: 1 branch
BranchTrueFalseTotal
(*i)->Debug(out,lvl); 580 0 580
475 else
476 0 ▶ out<<sep(lvl)<<"NULL\n";
Branch: 3 branches
BranchTrueFalseTotal
out<<sep(lvl)<<"NULL\n"; 0 0 0
out<<sep(lvl)<<"NULL\n"; 0 0 0
out<<sep(lvl)<<"NULL\n"; 0 0 0
477 }
478 260 }
479  
480 1607 void __Seq::AppendNode(__NodeBase * node)
481 {
482 1607 ▶ if(!seq_.empty())
Branch: 1 branch
BranchTrueFalseTotal
if(!seq_.empty()) 1607 0 1607
483 1607 ▶ if(__Text * cur = dynamic_cast<__Text *>(node))
Branch: 2 branches
BranchTrueFalseTotal
if(__Text * cur = dynamic_cast<__Text *>(node)) 1607 0 1607
if(__Text * cur = dynamic_cast<__Text *>(node)) 939 668 1607
484 939 ▶ if(__Text * prev = dynamic_cast<__Text *>(seq_.back())){
Branch: 2 branches
BranchTrueFalseTotal
if(__Text * prev = dynamic_cast<__Text *>(seq_.back())){ 939 0 939
if(__Text * prev = dynamic_cast<__Text *>(seq_.back())){ 922 17 939
485 922 *prev += *cur;
486 922 Delete(node);
487 922 return;
488 }
489 685 seq_.push_back(node);
490 }
491  
492 //class __Group
493 362 __Group::__Group(__NodeBase * node,int mark)
494 362 : node_(node)
495 362 , mark_(mark)
496 {
497 362 ▶ if(!Tools::IsSubexpMark(mark_))
Branch: 1 branch
BranchTrueFalseTotal
if(!Tools::IsSubexpMark(mark_)) 362 0 362
498 362 mark_ |= INDEX;
499 362 }
500  
501 0 __Group::~__Group()
502 {
503 362 Delete(node_);
504 0 }
505  
506 362 __NodeBase * __Group::Optimize(__ParseData & pdata)
507 {
508 362 ▶ if(!node_ || mark_ == '!')
Branch: 2 branches
BranchTrueFalseTotal
if(!node_ || mark_ == '!') 362 0 362
if(!node_ || mark_ == '!') 0 362 362
509 0 return REP_NULL;
510 362 __NodeBase * r = node_->Optimize(pdata);
511 362 ▶ if(r == REP_NULL)
Branch: 1 branch
BranchTrueFalseTotal
if(r == REP_NULL) 0 362 362
512 0 return REP_NULL;
513 362 ▶ else if(r){
Branch: 1 branch
BranchTrueFalseTotal
else if(r){ 265 97 362
514 265 Delete(node_);
515 265 node_ = r;
516 }
517 362 ▶ switch(mark_){
Branch: 1 branch
BranchTrueFalseTotal
switch(mark_){ 0 362 362
518 0 case ':':
519 case '=':
520 case '>':{
521 0 r = node_;
522 0 node_ = 0;
523 0 return r;}
524 362 default:;
525 }
526 362 mark_ = (mark_ & (INDEX - 1)) - 1;
527 362 return 0;
528 }
529  
530 35658 void __Group::RandString(__GenerateData & gdata) const
531 {
532 35658 ▶ assert(node_);
Branch: 1 branch
BranchTrueFalseTotal
assert(node_); 0 35658 35658
533 35658 ▶ assert(0 <= mark_ && mark_ < MAX_GROUPS);
Branch: 1 branch
BranchTrueFalseTotal
assert(0 <= mark_ && mark_ < MAX_GROUPS); 0 35658 35658
534 35658 ▶ if(mark_ >= gdata.refs_.size())
Branch: 1 branch
BranchTrueFalseTotal
if(mark_ >= gdata.refs_.size()) 35631 27 35658
535 35631 gdata.refs_.resize(mark_ + 1);
536 35658 ▶ gdata.refs_.back() = __RefValue(gdata.oss_.str().size(),__DZ_STRING::npos);
Branch: 1 branch
BranchTrueFalseTotal
gdata.refs_.back() = __RefValue(gdata.oss_.str().size(),__DZ_STRING::npos); 35658 0 35658
537 35658 node_->RandString(gdata);
538 35658 ▶ assert(mark_ < gdata.refs_.size());
Branch: 1 branch
BranchTrueFalseTotal
assert(mark_ < gdata.refs_.size()); 0 35658 35658
539 35658 ▶ gdata.refs_[mark_].second = gdata.oss_.str().size() - gdata.refs_[mark_].first;
Branch: 1 branch
BranchTrueFalseTotal
gdata.refs_[mark_].second = gdata.oss_.str().size() - gdata.refs_[mark_].first; 35658 0 35658
540 _OSS_OUT("__Group");
541 35658 }
542  
543 360 void __Group::Debug(std::ostream & out,int lvl) const
544 {
545 360 ▶ out<<sep(lvl)<<"Group(";
Branch: 3 branches
BranchTrueFalseTotal
out<<sep(lvl)<<"Group("; 360 0 360
out<<sep(lvl)<<"Group("; 360 0 360
out<<sep(lvl)<<"Group("; 360 0 360
546 360 switch(mark_){
547 0 case ':':out<<"?:";break;
548 0 case '=':out<<"?=";break;
549 0 case '!':out<<"?!";break;
550 0 case '>':out<<"?>";break;
551 360 default:out<<(mark_ & (INDEX - 1));
552 }
553 360 out<<")\n";
554 360 ++lvl;
555 360 ▶ if(node_)
Branch: 1 branch
BranchTrueFalseTotal
if(node_) 360 0 360
556 360 node_->Debug(out,lvl);
557 else
558 0 ▶ out<<sep(lvl)<<"NULL\n";
Branch: 3 branches
BranchTrueFalseTotal
out<<sep(lvl)<<"NULL\n"; 0 0 0
out<<sep(lvl)<<"NULL\n"; 0 0 0
out<<sep(lvl)<<"NULL\n"; 0 0 0
559 360 }
560  
561 //class __Select
562 13 __Select::__Select(__NodeBase * node)
563 13 ▶ : sel_(1,node)
Branch: 1 branch
BranchTrueFalseTotal
: sel_(1,node) 13 0 13
564 13 , sz_(0)
565 13 {}
566  
567 0 __Select::~__Select()
568 {
569 43 ▶ for(__Con::const_iterator i = sel_.begin(),e = sel_.end();i != e;++i)
Branch: 1 branch
BranchTrueFalseTotal
for(__Con::const_iterator i = sel_.begin(),e = sel_.end();i != e;++i) 30 13 43
570 30 Delete(*i);
571 0 }
572  
573 13 __NodeBase * __Select::Optimize(__ParseData & pdata)
574 {
575 13 ▶ if(sel_.empty())
Branch: 1 branch
BranchTrueFalseTotal
if(sel_.empty()) 0 13 13
576 0 return REP_NULL;
577 43 ▶ for(__Con::iterator i = sel_.begin(),e = sel_.end();i != e;++i)
Branch: 1 branch
BranchTrueFalseTotal
for(__Con::iterator i = sel_.begin(),e = sel_.end();i != e;++i) 30 13 43
578 30 ▶ if(*i){
Branch: 1 branch
BranchTrueFalseTotal
if(*i){ 30 0 30
579 30 ▶ __NodeBase * r = (*i)->Optimize(pdata);
Branch: 1 branch
BranchTrueFalseTotal
__NodeBase * r = (*i)->Optimize(pdata); 30 0 30
580 30 ▶ if(r){
Branch: 1 branch
BranchTrueFalseTotal
if(r){ 30 0 30
581 30 ▶ Delete(*i);
Branch: 1 branch
BranchTrueFalseTotal
Delete(*i); 30 0 30
582 30 ▶ *i = (r == REP_NULL ? 0 : r);
Branch: 1 branch
BranchTrueFalseTotal
*i = (r == REP_NULL ? 0 : r); 30 0 30
583 }
584 }
585 13 ▶ sel_.erase(std::remove_if(sel_.begin(),sel_.end(),__IsNull()),sel_.end());
Branch: 2 branches
BranchTrueFalseTotal
sel_.erase(std::remove_if(sel_.begin(),sel_.end(),__IsNull()),sel_.end()); 13 0 13
sel_.erase(std::remove_if(sel_.begin(),sel_.end(),__IsNull()),sel_.end()); 13 0 13
586 13 ▶ if(sel_.empty())
Branch: 1 branch
BranchTrueFalseTotal
if(sel_.empty()) 0 13 13
587 0 return REP_NULL;
588 13 ▶ if(sel_.size() == 1){
Branch: 1 branch
BranchTrueFalseTotal
if(sel_.size() == 1){ 0 13 13
589 0 __NodeBase * r = sel_[0];
590 0 sel_.clear();
591 0 return r;
592 }
593 13 sz_ = sel_.size();
594 13 return 0;
595 }
596  
597 1062 void __Select::RandString(__GenerateData & gdata) const
598 {
599 1062 ▶ if(sz_)
Branch: 1 branch
BranchTrueFalseTotal
if(sz_) 1062 0 1062
600 1062 sel_[rand() % sz_]->RandString(gdata);
601 _OSS_OUT("__Select");
602 1062 }
603  
604 12 void __Select::Debug(std::ostream & out,int lvl) const
605 {
606 12 ▶ out<<sep(lvl)<<"Select("<<sel_.size()<<")\n";
Branch: 5 branches
BranchTrueFalseTotal
out<<sep(lvl)<<"Select("<<sel_.size()<<")\n"; 12 0 12
out<<sep(lvl)<<"Select("<<sel_.size()<<")\n"; 12 0 12
out<<sep(lvl)<<"Select("<<sel_.size()<<")\n"; 12 0 12
out<<sep(lvl)<<"Select("<<sel_.size()<<")\n"; 12 0 12
out<<sep(lvl)<<"Select("<<sel_.size()<<")\n"; 12 0 12
607 12 ++lvl;
608 40 ▶ for(__Con::const_iterator i = sel_.begin(),e = sel_.end();i != e;++i)
Branch: 1 branch
BranchTrueFalseTotal
for(__Con::const_iterator i = sel_.begin(),e = sel_.end();i != e;++i) 28 12 40
609 28 ▶ if(*i)
Branch: 1 branch
BranchTrueFalseTotal
if(*i) 28 0 28
610 28 ▶ (*i)->Debug(out,lvl);
Branch: 1 branch
BranchTrueFalseTotal
(*i)->Debug(out,lvl); 28 0 28
611 else
612 0 ▶ out<<sep(lvl)<<"NULL\n";
Branch: 3 branches
BranchTrueFalseTotal
out<<sep(lvl)<<"NULL\n"; 0 0 0
out<<sep(lvl)<<"NULL\n"; 0 0 0
out<<sep(lvl)<<"NULL\n"; 0 0 0
613 12 }
614  
615 17 void __Select::AppendNode(__NodeBase * node)
616 {
617 17 sel_.push_back(node);
618 17 }
619  
620 //class __Ref
621 0 __Ref::__Ref(int index)
622 0 : index_(index)
623 0 {}
624  
625 0 __NodeBase * __Ref::Optimize(__ParseData & pdata)
626 {
627 0 --index_;
628 0 return 0;
629 }
630  
631 0 void __Ref::RandString(__GenerateData & gdata) const
632 {
633 0 ▶ assert(index_ < gdata.refs_.size());
Branch: 1 branch
BranchTrueFalseTotal
assert(index_ < gdata.refs_.size()); 0 0 0
634 0 const __RefValue & ref = gdata.refs_[index_];
635 0 ▶ __DZ_STRING str = gdata.oss_.str();
Branch: 1 branch
BranchTrueFalseTotal
__DZ_STRING str = gdata.oss_.str(); 0 0 0
636 0 ▶ if(ref.first < str.size())
Branch: 1 branch
BranchTrueFalseTotal
if(ref.first < str.size()) 0 0 0
637 0 ▶ gdata.oss_<<str.substr(ref.first,ref.second);
Branch: 2 branches
BranchTrueFalseTotal
gdata.oss_<<str.substr(ref.first,ref.second); 0 0 0
gdata.oss_<<str.substr(ref.first,ref.second); 0 0 0
638 _OSS_OUT("__Ref("<<index_<<")");
639 0 }
640  
641 0 void __Ref::Debug(std::ostream & out,int lvl) const
642 {
643 0 ▶ out<<sep(lvl)<<"Ref("<<index_<<")\n";
Branch: 5 branches
BranchTrueFalseTotal
out<<sep(lvl)<<"Ref("<<index_<<")\n"; 0 0 0
out<<sep(lvl)<<"Ref("<<index_<<")\n"; 0 0 0
out<<sep(lvl)<<"Ref("<<index_<<")\n"; 0 0 0
out<<sep(lvl)<<"Ref("<<index_<<")\n"; 0 0 0
out<<sep(lvl)<<"Ref("<<index_<<")\n"; 0 0 0
644 0 }
645  
646 //class __CRegxString
647 181 __CRegxString::__CRegxString()
648 181 : top_(0)
649 181 {}
650  
651 181 void __CRegxString::ParseRegx(const __DZ_STRING & regx,const Config * config)
652 {
653 181 ▶ uninit();
Branch: 1 branch
BranchTrueFalseTotal
uninit(); 181 0 181
654 181 ▶ regx_ = regx;
Branch: 1 branch
BranchTrueFalseTotal
regx_ = regx; 181 0 181
655 181 ▶ if(regx_.empty())
Branch: 1 branch
BranchTrueFalseTotal
if(regx_.empty()) 0 181 181
656 0 return;
657 181 Config def;
658 181 ▶ __ParseData pdata(config ? *config : def);
Branch: 1 branch
BranchTrueFalseTotal
__ParseData pdata(config ? *config : def); 181 0 181
659 181 ▶ top_ = processSeq(pdata).first;
Branch: 1 branch
BranchTrueFalseTotal
top_ = processSeq(pdata).first; 181 0 181
660 181 ▶ if(!top_)
Branch: 1 branch
BranchTrueFalseTotal
if(!top_) 0 181 181
661 0 return;
662 181 ▶ __NodeBase * r = top_->Optimize(pdata);
Branch: 1 branch
BranchTrueFalseTotal
__NodeBase * r = top_->Optimize(pdata); 181 0 181
663 181 ▶ if(r){
Branch: 1 branch
BranchTrueFalseTotal
if(r){ 4 177 181
664 4 ▶ Delete(top_);
Branch: 1 branch
BranchTrueFalseTotal
Delete(top_); 4 0 4
665 4 ▶ top_ = (r == __NodeBase::REP_NULL ? 0 : r);
Branch: 1 branch
BranchTrueFalseTotal
top_ = (r == __NodeBase::REP_NULL ? 0 : r); 4 0 4
666 }
667 181 ▶ if(top_)
Branch: 1 branch
BranchTrueFalseTotal
if(top_) 181 0 181
668 181 srand((unsigned int)time(0));
669 181 ▶}
Branch: 1 branch
BranchTrueFalseTotal
} 181 0 181
670  
671 17607 const __DZ_STRING & __CRegxString::RandString()
672 {
673 17607 str_.clear();
674 17607 ▶ if(top_){
Branch: 1 branch
BranchTrueFalseTotal
if(top_){ 17607 0 17607
675 17607 ▶ __DZ_OSTRINGSTREAM oss;
Branch: 1 branch
BranchTrueFalseTotal
__DZ_OSTRINGSTREAM oss; 17607 0 17607
676 17607 __GenerateData gdata(oss);
677 17607 ▶ top_->RandString(gdata);
Branch: 1 branch
BranchTrueFalseTotal
top_->RandString(gdata); 17607 0 17607
678 17607 ▶ str_ = oss.str();
Branch: 1 branch
BranchTrueFalseTotal
str_ = oss.str(); 17607 0 17607
679 17607 }
680 17607 return str_;
681 }
682  
683 177 void __CRegxString::Debug(std::ostream & out) const{
684 177 out<<"regx_ : "<<regx_<<"\nstructure :\n";
685 177 ▶ if(top_)
Branch: 1 branch
BranchTrueFalseTotal
if(top_) 177 0 177
686 177 top_->Debug(out,0);
687 else
688 0 out<<"NULL\n";
689 177 }
690  
691 362 void __CRegxString::uninit()
692 {
693 362 ▶ if(top_){
Branch: 1 branch
BranchTrueFalseTotal
if(top_){ 181 181 362
694 181 Delete(top_);
695 181 top_ = 0;
696 }
697 362 str_.clear();
698 362 }
699  
700 560 __CRegxString::__Ret __CRegxString::processSeq(__ParseData & pdata)
701 {
702 560 __Ret ret;
703 560 __NodeBase * cur = 0;
704 560 bool begin = true;
705 2939 ▶ for(const size_t e = regx_.length();pdata.i_ < e;++pdata.i_){
Branch: 1 branch
BranchTrueFalseTotal
for(const size_t e = regx_.length();pdata.i_ < e;++pdata.i_){ 2758 181 2939
706 2758 ▶ int ch = regx_[pdata.i_];
Branch: 1 branch
BranchTrueFalseTotal
int ch = regx_[pdata.i_]; 2758 0 2758
707 2758 ▶ if(begin){
Branch: 1 branch
BranchTrueFalseTotal
if(begin){ 741 2017 2758
708 741 ▶ if(Tools::IsBegin(ch)){
Branch: 1 branch
BranchTrueFalseTotal
if(Tools::IsBegin(ch)){ 181 560 741
709 181 ▶ cur = New<__Edge>(ch);
Branch: 1 branch
BranchTrueFalseTotal
cur = New<__Edge>(ch); 181 0 181
710 393 continue;
711 }
712 560 begin = false;
713 }
714 2577 ▶ if(Tools::IsRepeat(ch) && cur){
Branch: 3 branches
BranchTrueFalseTotal
if(Tools::IsRepeat(ch) && cur){ 13 2564 2577
if(Tools::IsRepeat(ch) && cur){ 13 0 13
if(Tools::IsRepeat(ch) && cur){ 13 2564 2577
715 13 ▶ int r = cur->Repeat(ch);
Branch: 1 branch
BranchTrueFalseTotal
int r = cur->Repeat(ch); 13 0 13
716 13 ▶ if(r){
Branch: 1 branch
BranchTrueFalseTotal
if(r){ 13 0 13
717 13 ▶ if(r == 1)
Branch: 1 branch
BranchTrueFalseTotal
if(r == 1) 13 0 13
718 13 ▶ cur = New<__Repeat>(cur,ch);
Branch: 1 branch
BranchTrueFalseTotal
cur = New<__Repeat>(cur,ch); 13 0 13
719 13 continue;
720 }
721 }
722 2564 ▶ if(Tools::IsRepeatBegin(ch)){
Branch: 1 branch
BranchTrueFalseTotal
if(Tools::IsRepeatBegin(ch)){ 199 2365 2564
723 199 ▶ cur = processRepeat(cur,pdata);
Branch: 1 branch
BranchTrueFalseTotal
cur = processRepeat(cur,pdata); 199 0 199
724 199 continue;
725 }
726 2365 ▶ appendNode(ret.first,cur);
Branch: 1 branch
BranchTrueFalseTotal
appendNode(ret.first,cur); 2365 0 2365
727 2365 ▶ ret.second = pdata.inEnds(ch);
Branch: 1 branch
BranchTrueFalseTotal
ret.second = pdata.inEnds(ch); 2365 0 2365
728 2365 ▶ if(ret.second)
Branch: 1 branch
BranchTrueFalseTotal
if(ret.second) 366 1999 2365
729 379 return ret;
730 1999 ▶ if(Tools::IsSelect(ch))
Branch: 1 branch
BranchTrueFalseTotal
if(Tools::IsSelect(ch)) 13 1986 1999
731 13 ▶ return processSelect(ret.first,pdata);
Branch: 1 branch
BranchTrueFalseTotal
return processSelect(ret.first,pdata); 13 0 13
732 1986 ▶ if(Tools::IsEnd(ch))
Branch: 1 branch
BranchTrueFalseTotal
if(Tools::IsEnd(ch)) 181 1805 1986
733 181 ▶ cur = New<__Edge>(ch);
Branch: 1 branch
BranchTrueFalseTotal
cur = New<__Edge>(ch); 181 0 181
734 1805 ▶ else if(Tools::IsAny(ch)){
Branch: 1 branch
BranchTrueFalseTotal
else if(Tools::IsAny(ch)){ 0 1805 1805
735 0 ▶ __Charset * set = New<__Charset>("\n",false);
Branch: 1 branch
BranchTrueFalseTotal
__Charset * set = New<__Charset>("\n",false); 0 0 0
736 0 ▶ set->Unique();
Branch: 1 branch
BranchTrueFalseTotal
set->Unique(); 0 0 0
737 0 cur = set;
738 1805 ▶ }else if(Tools::IsSetBegin(ch))
Branch: 1 branch
BranchTrueFalseTotal
}else if(Tools::IsSetBegin(ch)) 98 1707 1805
739 98 ▶ cur = processSet(pdata);
Branch: 1 branch
BranchTrueFalseTotal
cur = processSet(pdata); 98 0 98
740 1707 ▶ else if(Tools::IsGroupBegin(ch))
Branch: 1 branch
BranchTrueFalseTotal
else if(Tools::IsGroupBegin(ch)) 362 1345 1707
741 362 ▶ cur = processGroup(pdata);
Branch: 1 branch
BranchTrueFalseTotal
cur = processGroup(pdata); 362 0 362
742 1345 ▶ else if(Tools::IsSlash(ch))
Branch: 1 branch
BranchTrueFalseTotal
else if(Tools::IsSlash(ch)) 202 1143 1345
743 202 ▶ cur = processSlash(true,pdata).first;
Branch: 1 branch
BranchTrueFalseTotal
cur = processSlash(true,pdata).first; 202 0 202
744 else
745 1143 ▶ cur = New<__Text>(ch);
Branch: 1 branch
BranchTrueFalseTotal
cur = New<__Text>(ch); 1143 0 1143
746 }
747 181 ▶ appendNode(ret.first,cur);
Branch: 1 branch
BranchTrueFalseTotal
appendNode(ret.first,cur); 181 0 181
748 181 return ret;
749 }
750  
751 210 __CRegxString::__Ret __CRegxString::processSlash(bool bNode,__ParseData & pdata)
752 {
753 210 ++pdata.i_;
754 210 ▶ __Ret ret((__NodeBase *)0,pdata.i_ < regx_.length() ? Tools::TransSlash(regx_[pdata.i_]) : '\\');
Branch: 2 branches
BranchTrueFalseTotal
__Ret ret((__NodeBase *)0,pdata.i_ < regx_.length() ? Tools::TransSlash(regx_[pdata.i_]) : '\\'); 210 0 210
__Ret ret((__NodeBase *)0,pdata.i_ < regx_.length() ? Tools::TransSlash(regx_[pdata.i_]) : '\\'); 210 0 210
755 210 __Charset * set = 0;
756 210 switch(ret.second){
757 202 ▶ case 'd':set = New<__Charset>("0123456789",true);break;
Branch: 1 branch
BranchTrueFalseTotal
case 'd':set = New<__Charset>("0123456789",true);break; 202 0 202
758 0 ▶ case 'D':set = New<__Charset>("0123456789",false);break;
Branch: 1 branch
BranchTrueFalseTotal
case 'D':set = New<__Charset>("0123456789",false);break; 0 0 0
759 0 ▶ case 's':set = New<__Charset>(/*"\f\n\r\v"*/"\t ",true);break;
Branch: 1 branch
BranchTrueFalseTotal
case 's':set = New<__Charset>(/*"\f\n\r\v"*/"\t ",true);break; 0 0 0
760 0 ▶ case 'S':set = New<__Charset>(/*"\f\n\r\v"*/"\t ",false);break;
Branch: 1 branch
BranchTrueFalseTotal
case 'S':set = New<__Charset>(/*"\f\n\r\v"*/"\t ",false);break; 0 0 0
761 0 case 'w':{ //A-Za-z0-9_
762 0 ▶ set = New<__Charset>();
Branch: 1 branch
BranchTrueFalseTotal
set = New<__Charset>(); 0 0 0
763 0 ▶ set->AddRange('A','Z');
Branch: 1 branch
BranchTrueFalseTotal
set->AddRange('A','Z'); 0 0 0
764 0 ▶ set->AddRange('a','z');
Branch: 1 branch
BranchTrueFalseTotal
set->AddRange('a','z'); 0 0 0
765 0 ▶ set->AddRange('0','9');
Branch: 1 branch
BranchTrueFalseTotal
set->AddRange('0','9'); 0 0 0
766 0 ▶ set->AddChar('_');
Branch: 1 branch
BranchTrueFalseTotal
set->AddChar('_'); 0 0 0
767 0 break;}
768 0 case 'W':{ //^A-Za-z0-9_
769 0 ▶ set = New<__Charset>();
Branch: 1 branch
BranchTrueFalseTotal
set = New<__Charset>(); 0 0 0
770 0 ▶ set->AddRange('A','Z');
Branch: 1 branch
BranchTrueFalseTotal
set->AddRange('A','Z'); 0 0 0
771 0 ▶ set->AddRange('a','z');
Branch: 1 branch
BranchTrueFalseTotal
set->AddRange('a','z'); 0 0 0
772 0 ▶ set->AddRange('0','9');
Branch: 1 branch
BranchTrueFalseTotal
set->AddRange('0','9'); 0 0 0
773 0 ▶ set->AddChar('_');
Branch: 1 branch
BranchTrueFalseTotal
set->AddChar('_'); 0 0 0
774 0 ▶ set->Exclude();
Branch: 1 branch
BranchTrueFalseTotal
set->Exclude(); 0 0 0
775 0 break;}
776 210 default:;
777 }
778 210 ▶ if(set){
Branch: 1 branch
BranchTrueFalseTotal
if(set){ 202 8 210
779 202 ▶ set->Unique();
Branch: 1 branch
BranchTrueFalseTotal
set->Unique(); 202 0 202
780 202 ret.first = set;
781 8 ▶ }else if(bNode){
Branch: 1 branch
BranchTrueFalseTotal
}else if(bNode){ 0 8 8
782 0 ▶ if(Tools::IsDigit(ret.second)){
Branch: 1 branch
BranchTrueFalseTotal
if(Tools::IsDigit(ret.second)){ 0 0 0
783 0 int i = ret.second - '0';
784 0 ▶ if(!i)
Branch: 1 branch
BranchTrueFalseTotal
if(!i) 0 0 0
785 0 ret.second = 0;
786 0 ▶ else if(i <= pdata.ref_)
Branch: 1 branch
BranchTrueFalseTotal
else if(i <= pdata.ref_) 0 0 0
787 0 ▶ ret.first = New<__Ref>(i);
Branch: 1 branch
BranchTrueFalseTotal
ret.first = New<__Ref>(i); 0 0 0
788 }
789 0 ▶ if(!ret.first)
Branch: 1 branch
BranchTrueFalseTotal
if(!ret.first) 0 0 0
790 0 ▶ ret.first = New<__Text>(ret.second);
Branch: 1 branch
BranchTrueFalseTotal
ret.first = New<__Text>(ret.second); 0 0 0
791 }
792 210 return ret;
793 }
794  
795 98 __NodeBase * __CRegxString::processSet(__ParseData & pdata)
796 {
797 98 size_t bak = pdata.i_++;
798 98 __Charset * ret = New<__Charset>();
799 98 bool begin = true;
800 98 int prev = 0;
801 398 ▶ for(const size_t e = regx_.length();pdata.i_ < e;++pdata.i_){
Branch: 1 branch
BranchTrueFalseTotal
for(const size_t e = regx_.length();pdata.i_ < e;++pdata.i_){ 398 0 398
802 398 int ch = regx_[pdata.i_];
803 398 ▶ if(begin && Tools::IsBegin(ch)){
Branch: 3 branches
BranchTrueFalseTotal
if(begin && Tools::IsBegin(ch)){ 398 0 398
if(begin && Tools::IsBegin(ch)){ 0 398 398
if(begin && Tools::IsBegin(ch)){ 0 398 398
804 0 ret->Exclude();
805 0 begin = false;
806 0 continue;
807 }
808 398 ▶ if(Tools::IsDash(ch) && prev){
Branch: 3 branches
BranchTrueFalseTotal
if(Tools::IsDash(ch) && prev){ 118 280 398
if(Tools::IsDash(ch) && prev){ 118 0 118
if(Tools::IsDash(ch) && prev){ 118 280 398
809 118 int to = 0;
810 118 ▶ if(processRange(to,pdata)){
Branch: 2 branches
BranchTrueFalseTotal
if(processRange(to,pdata)){ 118 0 118
if(processRange(to,pdata)){ 118 0 118
811 118 ▶ ret->AddRange(prev,to);
Branch: 1 branch
BranchTrueFalseTotal
ret->AddRange(prev,to); 118 0 118
812 118 prev = 0;
813 118 continue;
814 }
815 }
816 280 ▶ if(prev)
Branch: 1 branch
BranchTrueFalseTotal
if(prev) 64 216 280
817 64 ret->AddChar(prev);
818 280 ▶ if(Tools::IsSetEnd(ch)){
Branch: 1 branch
BranchTrueFalseTotal
if(Tools::IsSetEnd(ch)){ 98 182 280
819 98 ret->Unique();
820 98 return ret;
821 }
822 182 ▶ if(Tools::IsSlash(ch)){
Branch: 1 branch
BranchTrueFalseTotal
if(Tools::IsSlash(ch)){ 8 174 182
823 8 ▶ __Ret s = processSlash(false,pdata);
Branch: 1 branch
BranchTrueFalseTotal
__Ret s = processSlash(false,pdata); 8 0 8
824 8 ▶ if(s.first){ //charset
Branch: 1 branch
BranchTrueFalseTotal
if(s.first){ //charset 0 8 8
825 0 ▶ ret->AddRange(dynamic_cast<__Charset *>(s.first));
Branch: 2 branches
BranchTrueFalseTotal
ret->AddRange(dynamic_cast<__Charset *>(s.first)); 0 0 0
ret->AddRange(dynamic_cast<__Charset *>(s.first)); 0 0 0
826 0 ▶ Delete(s.first);
Branch: 1 branch
BranchTrueFalseTotal
Delete(s.first); 0 0 0
827 0 prev = 0;
828 0 continue;
829 }
830 8 ch = s.second;
831 }
832 182 prev = ch;
833 }
834 0 Delete(ret);
835 0 pdata.i_ = bak;
836 0 ▶ return New<__Text>('[');
Branch: 1 branch
BranchTrueFalseTotal
return New<__Text>('['); 0 0 0
837 }
838  
839 362 __NodeBase * __CRegxString::processGroup(__ParseData & pdata)
840 {
841 362 int bak = pdata.i_++;
842 362 ▶ int mark = ignoreSubexpMarks(pdata);
Branch: 1 branch
BranchTrueFalseTotal
int mark = ignoreSubexpMarks(pdata); 362 0 362
843 362 ▶ pdata.ends_.push_back(')');
Branch: 1 branch
BranchTrueFalseTotal
pdata.ends_.push_back(')'); 362 0 362
844 362 ▶ if(!mark)
Branch: 1 branch
BranchTrueFalseTotal
if(!mark) 362 0 362
845 362 mark = ++pdata.ref_;
846 362 ▶ __Ret ret = processSeq(pdata);
Branch: 1 branch
BranchTrueFalseTotal
__Ret ret = processSeq(pdata); 362 0 362
847 362 pdata.ends_.pop_back();
848 362 ▶ if(ret.second)
Branch: 1 branch
BranchTrueFalseTotal
if(ret.second) 362 0 362
849 362 ▶ return New<__Group>(ret.first,mark);
Branch: 1 branch
BranchTrueFalseTotal
return New<__Group>(ret.first,mark); 362 0 362
850 0 ▶ Delete(ret.first);
Branch: 1 branch
BranchTrueFalseTotal
Delete(ret.first); 0 0 0
851 0 pdata.i_ = bak;
852 0 ▶ return New<__Text>('(');
Branch: 1 branch
BranchTrueFalseTotal
return New<__Text>('('); 0 0 0
853 }
854  
855 13 __CRegxString::__Ret __CRegxString::processSelect(__NodeBase * node,__ParseData & pdata)
856 {
857 13 ▶ __Ret ret(New<__Select>(node),0);
Branch: 1 branch
BranchTrueFalseTotal
__Ret ret(New<__Select>(node),0); 13 0 13
858 13 ▶ pdata.ends_.push_back('|');
Branch: 1 branch
BranchTrueFalseTotal
pdata.ends_.push_back('|'); 13 0 13
859 17 ▶ for(const size_t e = regx_.length();pdata.i_ < e;){
Branch: 1 branch
BranchTrueFalseTotal
for(const size_t e = regx_.length();pdata.i_ < e;){ 17 0 17
860 17 ++pdata.i_;
861 17 ▶ __Ret r = processSeq(pdata);
Branch: 1 branch
BranchTrueFalseTotal
__Ret r = processSeq(pdata); 17 0 17
862 17 ▶ ret.first->AppendNode(r.first);
Branch: 1 branch
BranchTrueFalseTotal
ret.first->AppendNode(r.first); 17 0 17
863 17 ▶ if(r.second > 1){
Branch: 1 branch
BranchTrueFalseTotal
if(r.second > 1){ 13 4 17
864 13 ret.second = r.second - 1;
865 13 break;
866 }
867 }
868 13 pdata.ends_.pop_back();
869 13 return ret;
870 }
871  
872 199 __NodeBase * __CRegxString::processRepeat(__NodeBase * node,__ParseData & pdata)
873 {
874 199 ▶ if(node && node->Repeat(0)){
Branch: 3 branches
BranchTrueFalseTotal
if(node && node->Repeat(0)){ 199 0 199
if(node && node->Repeat(0)){ 199 0 199
if(node && node->Repeat(0)){ 199 0 199
875 199 size_t bak = pdata.i_++;
876 199 int min = 0,max = __Repeat::INFINITE;
877 199 ▶ switch(processInt(min,pdata)){
Branch: 1 branch
BranchTrueFalseTotal
switch(processInt(min,pdata)){ 199 0 199
878 12 case ',':
879 12 ++pdata.i_;
880 12 ▶ if(processInt(max,pdata) == '}')
Branch: 2 branches
BranchTrueFalseTotal
if(processInt(max,pdata) == '}') 12 0 12
if(processInt(max,pdata) == '}') 12 0 12
881 199 ▶ return New<__Repeat>(node,min,(min < max ? max : min));
Branch: 2 branches
BranchTrueFalseTotal
return New<__Repeat>(node,min,(min < max ? max : min)); 12 0 12
return New<__Repeat>(node,min,(min < max ? max : min)); 12 0 12
882 0 break;
883 187 case '}':
884 187 ▶ return New<__Repeat>(node,min,min);
Branch: 1 branch
BranchTrueFalseTotal
return New<__Repeat>(node,min,min); 187 0 187
885 0 default:;
886 }
887 0 pdata.i_ = bak;
888 }
889 0 ▶ return New<__Text>('{');
Branch: 1 branch
BranchTrueFalseTotal
return New<__Text>('{'); 0 0 0
890 }
891  
892 211 int __CRegxString::processInt(int & result,__ParseData & pdata)
893 {
894 211 bool begin = true;
895 475 ▶ for(const size_t e = regx_.length();pdata.i_ < e;++pdata.i_){
Branch: 1 branch
BranchTrueFalseTotal
for(const size_t e = regx_.length();pdata.i_ < e;++pdata.i_){ 475 0 475
896 475 int ch = regx_[pdata.i_];
897 475 ▶ if(Tools::IsDigit(ch)){
Branch: 1 branch
BranchTrueFalseTotal
if(Tools::IsDigit(ch)){ 264 211 475
898 264 ch = Tools::TransDigit(ch);
899 264 ▶ if(begin){
Branch: 1 branch
BranchTrueFalseTotal
if(begin){ 211 53 264
900 211 result = ch;
901 211 begin = false;
902 }else{
903 53 result *= 10;
904 53 ▶ if(result < 0)
Branch: 1 branch
BranchTrueFalseTotal
if(result < 0) 0 53 53
905 0 return 0;
906 53 result += ch;
907 }
908 }else
909 211 return ch;
910 }
911 0 return 0;
912 }
913  
914 118 bool __CRegxString::processRange(int & result,__ParseData & pdata)
915 {
916 118 ▶ if(++pdata.i_ < regx_.size() && regx_[pdata.i_] != ']'){
Branch: 3 branches
BranchTrueFalseTotal
if(++pdata.i_ < regx_.size() && regx_[pdata.i_] != ']'){ 118 0 118
if(++pdata.i_ < regx_.size() && regx_[pdata.i_] != ']'){ 118 0 118
if(++pdata.i_ < regx_.size() && regx_[pdata.i_] != ']'){ 118 0 118
917 118 result = regx_[pdata.i_];
918 118 return true;
919 }
920 0 --pdata.i_;
921 0 return false;
922 }
923  
924 362 int __CRegxString::ignoreSubexpMarks(__ParseData & pdata)
925 {
926 362 int ret = 0;
927 362 ▶ if(pdata.i_ + 1 < regx_.size()){
Branch: 1 branch
BranchTrueFalseTotal
if(pdata.i_ + 1 < regx_.size()){ 362 0 362
928 362 ret = Tools::IsSubexpMark(&regx_[pdata.i_]);
929 362 ▶ if(ret)
Branch: 1 branch
BranchTrueFalseTotal
if(ret) 0 362 362
930 0 pdata.i_ += 2;
931 }
932 362 return ret;
933 }
934  
935 NAMESAPCE_END
« regxstring.cpp ↑ Summary harness.cpp »