]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/PosRegExp.cxx
8 //Up: /[A-Z \x80-\x9f \xf0 ]/x
9 //Lo: /[a-z \xa0-\xaf \xe0-\xef \xf1 ]/x
10 //Wd: /[\d _ A-Z a-z \xa0-\xaf \xe0-\xf1 \x80-\x9f]/x
12 SCharData UCData
= {0x0, 0x0, 0x7fffffe, 0x0, 0xffffffff, 0x0, 0x0, 0x10000},
13 LCData
= {0x0, 0x0, 0x0, 0x7fffffe, 0x0, 0xffff, 0x0, 0x2ffff},
14 WdData
= {0x0, 0x3ff0000, 0x87fffffe, 0x7fffffe, 0xffffffff, 0xffff, 0x0, 0x3ffff},
15 DigData
= {0x0, 0x3ff0000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
17 SCharData UCData = {0x0, 0x0, 0x7fffffe, 0x0, 0x0, 0x0, 0xffffffff, 0x0},
18 LCData = {0x0, 0x0, 0x0, 0x7fffffe, 0x0, 0x0, 0x0, 0xffffffff},
19 WdData = {0x0, 0x3ff0000, 0x87fffffe, 0x7fffffe, 0x0, 0x0, 0xffffffff, 0xffffffff},
20 DigData = {0x0, 0x3ff0000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
23 ///////////////////////////////////////////////
25 int GetNumber(int *str
,int s
,int e
) {
28 for(int i
= e
-1; i
>= s
; i
--) {
29 if (str
[i
] > '9' || str
[i
] < '0') return -1;
30 num
+= (str
[i
] - 0x30)*r
;
37 if (e == s) return -1;
38 for (int i = s;i < e;i++)
39 tmp[i-s] = (char)Str[i];
46 bool IsDigit(char Symb
) {
47 return DigData
.GetBit(Symb
);
49 bool IsWord(char Symb
) {
50 return WdData
.GetBit(Symb
);
52 bool IsUpperCase(char Symb
) {
53 return UCData
.GetBit(Symb
);
55 bool IsLowerCase(char Symb
) {
56 return LCData
.GetBit(Symb
);
58 char LowCase(char Chr
) {
59 if (UCData
.GetBit(Chr
))
64 ///////////////////////////////////////////////
66 SRegInfo::SRegInfo() {
71 SRegInfo::~SRegInfo() {
72 if (Next
) delete Next
;
80 if (Op
> ReBlockOps
&& Op
< ReSymbolOps
|| Op
== ReBrackets
)
86 ///////////////////////////////////////////////
88 void SCharData::SetBit(unsigned char Bit
) {
90 CArr
[p
] |= (1 << Bit%8
);
92 void SCharData::ClearBit(unsigned char Bit
) {
94 CArr
[p
] &= ~(1 << Bit%8
);
96 bool SCharData::GetBit(unsigned char Bit
) {
97 int p
= (unsigned char)Bit
/8;
98 return (CArr
[p
] & (1 << Bit%8
))!=0;
101 /////////////////////////////////////////////////////////////////
102 ////////////////////// RegExp Class ///////////////////////////
103 /////////////////////////////////////////////////////////////////
105 PosRegExp::PosRegExp() {
113 PosRegExp::~PosRegExp() {
114 if (Info
) delete Info
;
117 bool PosRegExp::SetExpr(const char *Expr
) {
118 if (!this) return false;
121 if (SetExprLow(Expr
)) Error
= false;
124 bool PosRegExp::isok() {
129 bool PosRegExp::SetExprLow(const char *Expr
) {
130 int Len
= strlen(Expr
);
132 int i
,j
,s
= 0,pos
,tmp
;
133 int EnterBr
= 0,EnterGr
= 0,EnterFg
= 0;
135 if (Info
) delete Info
;
137 Exprn
= new int[Len
];
141 if (Expr
[0] == '/') s
++;
144 for (i
= Len
; i
> 0 && !Ok
;i
--)
145 if (Expr
[i
] == '/') {
148 for (int j
= i
+1; Expr
[j
]; j
++) {
149 if (Expr
[j
] == 'i') NoCase
= true;
150 if (Expr
[j
] == 'x') Extend
= true;
153 if (!Ok
) return false;
155 ////////////////////////////////
156 for (j
= 0,pos
= 0; j
< Len
; j
++,pos
++) {
157 if (Extend
&& Expr
[j
+s
] == ' ') {
162 Exprn
[pos
] = (int)(unsigned char)Expr
[j
+s
];
164 if (Expr
[j
+s
] == BackSlash
) {
165 switch (Expr
[j
+s
+1]) {
167 Exprn
[pos
] = ReDigit
;
170 Exprn
[pos
] = ReNDigit
;
173 Exprn
[pos
] = ReWordSymb
;
176 Exprn
[pos
] = ReNWordSymb
;
179 Exprn
[pos
] = ReWSpace
;
182 Exprn
[pos
] = ReNWSpace
;
185 Exprn
[pos
] = ReUCase
;
188 Exprn
[pos
] = ReNUCase
;
200 Exprn
[pos
] = ReWBound
;
203 Exprn
[pos
] = ReNWBound
;
206 Exprn
[pos
] = RePreNW
;
209 Exprn
[pos
] = ReStart
;
215 tmp
= toupper(Expr
[j
+s
+2])-0x30;
216 tmp
= (tmp
>9?tmp
-7:tmp
)<<4;
217 tmp
+= (toupper(Expr
[j
+s
+3])-0x30)>9?toupper(Expr
[j
+s
+3])-0x37:(toupper(Expr
[j
+s
+3])-0x30);
222 tmp
= Expr
[j
+s
+2] - 0x30;
223 if (tmp
>= 0 && tmp
<= 9) {
225 tmp
= 10 + Expr
[j
+s
+3] - 0x30;
226 if (tmp
>= 10 && tmp
<= 19) j
++;
229 Exprn
[pos
] = ReBkTrace
+ tmp
;
234 tmp
= Expr
[j
+s
+1] - 0x30;
235 if (tmp
>= 0 && tmp
<= 9) {
237 tmp
= 10 + Expr
[j
+s
+2] - 0x30;
238 if (tmp
>= 10 && tmp
<= 19) j
++;
241 Exprn
[pos
] = ReBkBrack
+ tmp
;
244 Exprn
[pos
] = Expr
[j
+s
+1];
250 if (Expr
[j
+s
] == ']') {
251 Exprn
[pos
] = ReEnumE
;
252 if (EnterFg
|| !EnterGr
) return false;
255 if (Expr
[j
+s
] == '-' && EnterGr
) Exprn
[pos
] = ReFrToEnum
;
257 if (EnterGr
) continue;
259 if (Expr
[j
+s
] == '[' && Expr
[j
+s
+1] == '^') {
260 Exprn
[pos
] = ReNEnumS
;
261 if (EnterFg
) return false;
266 if (Expr
[j
+s
] == '*' && Expr
[j
+s
+1] == '?') {
267 Exprn
[pos
] = ReNGMul
;
271 if (Expr
[j
+s
] == '+' && Expr
[j
+s
+1] == '?') {
272 Exprn
[pos
] = ReNGPlus
;
276 if (Expr
[j
+s
] == '?' && Expr
[j
+s
+1] == '?') {
277 Exprn
[pos
] = ReNGQuest
;
281 if (Expr
[j
+s
] == '?' && Expr
[j
+s
+1] == '#' &&
282 Expr
[j
+s
+2]>='0' && Expr
[j
+s
+2]<='9') {
283 Exprn
[pos
] = ReBehind
+Expr
[j
+s
+2]-0x30;
287 if (Expr
[j
+s
] == '?' && Expr
[j
+s
+1] == '~' &&
288 Expr
[j
+s
+2]>='0' && Expr
[j
+s
+2]<='9') {
289 Exprn
[pos
] = ReNBehind
+Expr
[j
+s
+2]-0x30;
293 if (Expr
[j
+s
] == '?' && Expr
[j
+s
+1] == '=') {
294 Exprn
[pos
] = ReAhead
;
298 if (Expr
[j
+s
] == '?' && Expr
[j
+s
+1] == '!') {
299 Exprn
[pos
] = ReNAhead
;
304 if (Expr
[j
+s
] == '(') {
305 Exprn
[pos
] = ReLBrack
;
306 if (EnterFg
) return false;
309 if (Expr
[j
+s
] == ')') {
310 Exprn
[pos
] = ReRBrack
;
311 if (!EnterBr
|| EnterFg
) return false;
314 if (Expr
[j
+s
] == '[') {
315 Exprn
[pos
] = ReEnumS
;
316 if (EnterFg
) return false;
319 if (Expr
[j
+s
] == '{') {
320 Exprn
[pos
] = ReRangeS
;
321 if (EnterFg
) return false;
324 if (Expr
[j
+s
] == '}' && Expr
[j
+s
+1] == '?') {
325 Exprn
[pos
] = ReNGRangeE
;
326 if (!EnterFg
) return false;
331 if (Expr
[j
+s
] == '}') {
332 Exprn
[pos
] = ReRangeE
;
333 if (!EnterFg
) return false;
337 if (Expr
[j
+s
] == '^') Exprn
[pos
] = ReSoL
;
338 if (Expr
[j
+s
] == '$') Exprn
[pos
] = ReEoL
;
339 if (Expr
[j
+s
] == '.') Exprn
[pos
] = ReAnyChr
;
340 if (Expr
[j
+s
] == '*') Exprn
[pos
] = ReMul
;
341 if (Expr
[j
+s
] == '+') Exprn
[pos
] = RePlus
;
342 if (Expr
[j
+s
] == '?') Exprn
[pos
] = ReQuest
;
343 if (Expr
[j
+s
] == '|') Exprn
[pos
] = ReOr
;
345 if (EnterGr
|| EnterBr
|| EnterFg
) return false;
347 Info
->Op
= ReBrackets
;
348 Info
->un
.Param
= new SRegInfo
;
349 Info
->s
= CurMatch
++;
351 if (!SetStructs(Info
->un
.Param
,0,pos
)) return false;
357 void PosRegExp::Optimize() {
358 PRegInfo Next
= Info
;
361 if (Next
->Op
== ReBrackets
|| Next
->Op
== RePlus
|| Next
->Op
== ReNGPlus
) {
362 Next
= Next
->un
.Param
;
365 if (Next
->Op
== ReSymb
) {
366 if (Next
->un
.Symb
& 0xFF00 && Next
->un
.Symb
!= ReSoL
&& Next
->un
.Symb
!= ReWBound
)
368 FirstChar
= Next
->un
.Symb
;
375 bool PosRegExp::SetStructs(PRegInfo
&re
,int start
,int end
) {
376 PRegInfo Next
,Prev
,Prev2
;
377 int comma
,st
,en
,ng
,i
, j
,k
;
381 if (end
- start
< 0) return false;
383 for (i
= start
; i
< end
; i
++) {
386 if (Exprn
[i
] > ReBlockOps
&& Exprn
[i
] < ReSymbolOps
) {
388 Next
->Op
= (EOps
)Exprn
[i
];
392 if (Exprn
[i
] == ReRangeS
) {
397 for (j
= i
;j
< end
;j
++) {
398 if (Exprn
[j
] == ReNGRangeE
) {
403 if (Exprn
[j
] == ReRangeE
) {
407 if ((char)Exprn
[j
] == ',')
410 if (en
== -1) return false;
411 if (comma
== -1) comma
= en
;
412 Next
->s
= (char)GetNumber(Exprn
,st
+1,comma
);
414 Next
->e
= (char)GetNumber(Exprn
,comma
+1,en
);
418 Next
->Op
= ng
?ReNGRangeNM
:ReRangeNM
;
421 Next
->Op
= ng
?ReNGRangeN
:ReRangeN
;
427 if (Exprn
[i
] == ReEnumS
|| Exprn
[i
] == ReNEnumS
) {
428 Next
->Op
= (Exprn
[i
] == ReEnumS
)?ReEnum
:ReNEnum
;
429 for (j
= i
+1;j
< end
;j
++) {
430 if (Exprn
[j
] == ReEnumE
)
433 if (j
== end
) return false;
434 Next
->un
.ChrClass
= new SCharData
;
435 memset(Next
->un
.ChrClass
, 0, 32);
436 for (j
= i
+1;Exprn
[j
] != ReEnumE
;j
++) {
437 if (Exprn
[j
+1] == ReFrToEnum
) {
438 for (i
= (Exprn
[j
]&0xFF); i
< (Exprn
[j
+2]&0xFF);i
++)
439 Next
->un
.ChrClass
->SetBit(i
&0xFF);
445 for (k
= 0x30;k
< 0x40;k
++)
446 if (IsDigit((char)k
))
447 Next
->un
.ChrClass
->SetBit(k
);
450 for (k
= 0x30;k
< 0x40;k
++)
451 if (!IsDigit((char)k
))
452 Next
->un
.ChrClass
->SetBit(k
);
453 Next
->un
.ChrClass
->ClearBit(0x0a);
454 Next
->un
.ChrClass
->ClearBit(0x0d);
457 for (k
= 0;k
< 256;k
++)
459 Next
->un
.ChrClass
->SetBit(k
);
462 for (k
= 0;k
< 256;k
++)
463 if (!IsWord((char)k
))
464 Next
->un
.ChrClass
->SetBit(k
);
465 Next
->un
.ChrClass
->ClearBit(0x0a);
466 Next
->un
.ChrClass
->ClearBit(0x0d);
469 Next
->un
.ChrClass
->SetBit(0x20);
470 Next
->un
.ChrClass
->SetBit(0x09);
473 memset(Next
->un
.ChrClass
->IArr
, 0xFF, 32);
474 Next
->un
.ChrClass
->ClearBit(0x20);
475 Next
->un
.ChrClass
->ClearBit(0x09);
476 Next
->un
.ChrClass
->ClearBit(0x0a);
477 Next
->un
.ChrClass
->ClearBit(0x0d);
480 if (!(Exprn
[j
]&0xFF00))
481 Next
->un
.ChrClass
->SetBit(Exprn
[j
]&0xFF);
489 if (Exprn
[i
] == ReLBrack
) {
491 for (j
= i
+1;j
< end
;j
++) {
492 if (Exprn
[j
] == ReLBrack
) EnterBr
++;
493 if (Exprn
[j
] == ReRBrack
) EnterBr
--;
496 if (EnterBr
) return false;
497 Next
->Op
= ReBrackets
;
498 Next
->un
.Param
= new SRegInfo
;
499 Next
->un
.Param
->Parent
= Next
;
500 Next
->s
= CurMatch
++;
501 if (CurMatch
> MatchesNum
) CurMatch
= MatchesNum
;
502 if (!SetStructs(Next
->un
.Param
,i
+1,j
)) return false;
506 if ((Exprn
[i
]&0xFF00) == ReBkTrace
) {
507 Next
->Op
= ReBkTrace
;
508 Next
->un
.Symb
= Exprn
[i
]&0xFF;
511 if ((Exprn
[i
]&0xFF00) == ReBkBrack
) {
512 Next
->Op
= ReBkBrack
;
513 Next
->un
.Symb
= Exprn
[i
]&0xFF;
516 if ((Exprn
[i
]&0xFF00) == ReBehind
) {
518 Next
->s
= Exprn
[i
]&0xFF;
521 if ((Exprn
[i
]&0xFF00) == ReNBehind
) {
522 Next
->Op
= ReNBehind
;
523 Next
->s
= Exprn
[i
]&0xFF;
527 if (Exprn
[i
] >= ReAnyChr
&& Exprn
[i
] < ReTemp
|| Exprn
[i
] < 0x100) {
529 Next
->un
.Symb
= Exprn
[i
];
533 if (Add
&& i
!= end
-1) {
534 Next
->Next
= new SRegInfo
;
535 Next
->Next
->Parent
= Next
->Parent
;
542 if (Next
->Op
> ReBlockOps
&& Next
->Op
< ReSymbolOps
) {
543 if (!Prev
) return false;
544 if (!Prev2
) re
= Next
;
545 else Prev2
->Next
= Next
;
546 //if (Prev->Op > ReBlockOps && Prev->Op < ReSymbolOps) return false;
549 Next
->un
.Param
= Prev
;
560 /////////////////////////////////////////////////////////////////
561 ///////////////////////// Parsing /////////////////////////////
562 /////////////////////////////////////////////////////////////////
564 bool PosRegExp::CheckSymb(int Symb
,bool Inc
) {
569 if (posParse
>= posEnd
) return false;
570 ch
= CharAt(posParse
,param
);
571 Res
= ch
!= '\r' && ch
!= '\n';
572 if (Res
&& Inc
) posParse
++;
575 if (posStart
== posParse
)
577 ch
= CharAt(posParse
-1,param
);
578 return ch
== '\n' || ch
== '\r';
580 if (posEnd
== posParse
)
582 ch
= CharAt(posParse
,param
);
583 return ch
== '\n' || ch
== '\r';
585 if (posParse
>= posEnd
) return false;
586 ch
= CharAt(posParse
,param
);
587 Res
= (ch
>= 0x30 && ch
<= 0x39);
588 if (Res
&& Inc
) posParse
++;
591 if (posParse
>= posEnd
) return false;
592 ch
= CharAt(posParse
,param
);
593 Res
= !(ch
>= 0x30 && ch
<= 0x39) && ch
!= '\r' && ch
!= '\n';
594 if (Res
&& Inc
) posParse
++;
597 if (posParse
>= posEnd
) return false;
598 Res
= IsWord(CharAt(posParse
,param
));
599 if (Res
&& Inc
) posParse
++;
602 if (posParse
>= posEnd
) return false;
603 ch
= CharAt(posParse
,param
);
604 Res
= !IsWord(ch
) && ch
!= '\r' && ch
!= '\n';
605 if (Res
&& Inc
) posParse
++;
608 if (posParse
>= posEnd
) return false;
609 ch
= CharAt(posParse
,param
);
610 Res
= (ch
== 0x20 || ch
== '\t');
611 if (Res
&& Inc
) posParse
++;
614 if (posParse
>= posEnd
) return false;
615 ch
= CharAt(posParse
,param
);
616 Res
= !(ch
== 0x20 || ch
== '\t') && ch
!= '\r' && ch
!= '\n';
617 if (Res
&& Inc
) posParse
++;
620 if (posParse
>= posEnd
) return false;
621 Res
= IsUpperCase(CharAt(posParse
,param
));
622 if (Res
&& Inc
) posParse
++;
625 if (posParse
>= posEnd
) return false;
626 Res
= IsLowerCase(CharAt(posParse
,param
));
627 if (Res
&& Inc
) posParse
++;
630 if (posParse
>= posEnd
) return true;
631 ch
= CharAt(posParse
,param
);
632 return IsWord(CharAt(posParse
,param
)) && (posParse
== posStart
|| !IsWord(CharAt(posParse
-1,param
)));
634 if (posParse
>= posEnd
) return true;
635 return !IsWord(CharAt(posParse
,param
)) && IsWord(CharAt(posParse
-1,param
));
637 if (posParse
>= posEnd
) return true;
638 return (posParse
== posStart
|| !IsWord(CharAt(posParse
-1,param
)));
640 Matches
->s
[0] = (posParse
-posStart
);
643 Matches
->e
[0] = (posParse
-posStart
);
646 if ((Symb
& 0xFF00) || posParse
>= posEnd
) return false;
648 if (LowCase(CharAt(posParse
,param
)) != LowCase((char)Symb
&0xFF)) return false;
650 if (CharAt(posParse
,param
) != (char)(Symb
&0xFF)) return false;
656 bool PosRegExp::LowParseRe(PRegInfo
&Next
) {
663 if (!CheckSymb(Next
->un
.Symb
,true)) return false;
668 if (!posBkStr
| !BkTrace
) return false;
671 for (i
= BkTrace
->s
[sv
]; i
< BkTrace
->e
[sv
]; i
++) {
672 if (CharAt(posStr
,param
) != CharAt(posBkStr
+i
,param
) || posEnd
== posStr
) return false;
680 if (Matches
->s
[sv
] == -1 || Matches
->e
[sv
] == -1) return false;
681 for (i
= Matches
->s
[sv
]; i
< Matches
->e
[sv
]; i
++) {
682 if (CharAt(posStr
,param
) != CharAt(posStart
+i
,param
) || posEnd
== posStr
) return false;
691 if (!LowParse(Next
->un
.Param
)) return false;
698 if (LowParse(Next
->un
.Param
)) return false;
703 if (!LowParse(Next
->un
.Param
)) return false;
708 if (LowParse(Next
->un
.Param
)) return false;
712 if (posParse
>= posEnd
) return false;
713 if (!Next
->un
.ChrClass
->GetBit(CharAt(posParse
,param
))) return false;
717 if (posParse
>= posEnd
) return false;
718 if (Next
->un
.ChrClass
->GetBit(CharAt(posParse
,param
))) return false;
723 sv
= posParse
-posStart
;
725 if (LowParse(Next
->un
.Param
)) {
726 if (match
|| (Matches
->s
[match
] == -1))
727 Matches
->s
[match
] = sv
;
728 if (match
|| (Matches
->e
[match
] == -1))
729 Matches
->e
[match
] = posParse
-posStart
;
736 while (LowParse(Next
->un
.Param
));
737 while(!LowCheckNext(Next
) && posStr
< posParse
) posParse
--;
741 if (LowCheckNext(Next
)) break;
742 } while (LowParse(Next
->un
.Param
));
747 while (LowParse(Next
->un
.Param
))
749 if (!match
) return false;
750 while(!LowCheckNext(Next
) && posStr
< posParse
) posParse
--;
753 if (!LowParse(Next
->un
.Param
)) return false;
755 if (LowCheckNext(Next
)) break;
756 } while (LowParse(Next
->un
.Param
));
759 LowParse(Next
->un
.Param
);
762 if (LowCheckNext(Next
)) break;
763 if (!LowParse(Next
->un
.Param
)) return false;
767 // posStr = posParse;
768 if (LowParse(Next
->un
.Param
)) {
769 while (OrNext
&& OrNext
->Op
== ReOr
)
770 OrNext
= OrNext
->Next
;
771 /*if (!LowCheckNext(OrNext)){
781 while (LowParse(Next
->un
.Param
)) i
++; // ???
788 } while(!LowCheckNext(Next
) && posStr
< posParse
--);
793 while (LowParse(Next
->un
.Param
)) {
795 if (i
>= Next
->s
&& LowCheckNext(Next
)) // ???
806 while (i
< Next
->s
&& LowParse(Next
->un
.Param
)) // ???
812 while (i
< Next
->e
&& LowParse(Next
->un
.Param
)) // ???
815 while(!LowCheckNext(Next
)) {
827 while (i
< Next
->s
&& LowParse(Next
->un
.Param
)) // ???
833 while(!LowCheckNext(Next
)) {
835 if (!LowParse(Next
->un
.Param
) || i
> Next
->e
) { // ???
845 bool PosRegExp::LowCheckNext(PRegInfo Re
) {
850 if (Next
&& Next
->Op
== ReOr
)
851 while (Next
&& Next
->Op
== ReOr
)
853 if (Next
->Next
&& !LowParse(Next
->Next
)) {
861 if (Ok
!= false) Ok
= true;
865 bool PosRegExp::LowParse(PRegInfo Re
) {
866 while(Re
&& posParse
<= posEnd
) {
867 if (!LowParseRe(Re
)) return false;
868 if (Re
) Re
= Re
->Next
;
873 bool PosRegExp::QuickCheck() {
874 if (!NoMoves
|| !FirstChar
)
878 if (posParse
!= posStart
) return false;
881 return IsWord(CharAt(posParse
,param
)) && (posParse
== posStart
|| !IsWord(CharAt(posParse
-1,param
)));
883 if (NoCase
&& LowCase(CharAt(posParse
,param
)) != LowCase(FirstChar
)) return false;
884 if (!NoCase
&& CharAt(posParse
,param
) != (char)FirstChar
) return false;
889 bool PosRegExp::ParseRe(int posStr
) {
890 if (Error
) return false;
893 if (!QuickCheck()) return false;
895 for (int i
= 0; i
< MatchesNum
; i
++)
896 Matches
->s
[i
] = Matches
->e
[i
] = -1;
897 Matches
->CurMatch
= CurMatch
;
902 if (!LowParse(Info
)) {
903 if (NoMoves
) return false;
907 } while(posParse
!= posEnd
+1);
915 bool PosRegExp::Parse(int posStr
,int posSol
, int posEol
, PMatches Mtch
, int Moves
) {
916 if (!this) return false;
919 if (Moves
!= -1) NoMoves
= Moves
!=0;
923 bool r
= ParseRe(posStr
);
928 bool PosRegExp::Parse(int posStr
, int posStop
, PMatches Mtch
) {
929 if (!this) return false;
933 return ParseRe(posStr
);
936 bool PosRegExp::SetNoMoves(bool Moves
) {
941 bool PosRegExp::SetBkTrace(int posStr
,PMatches Trace
) {
947 #define EVAL_MATCHES 16
948 #define EVAL_CHUNKSIZE 256
950 #define EVAL_LOWERCASE 1
951 #define EVAL_UPPERCASE 2
952 #define EVAL_LOWERCASE_NEXT 4
953 #define EVAL_UPPERCASE_NEXT 8
955 bool PosRegExp::Evaluate(char *Expr
, int posStr
, PMatches Mtch
, char **Res
) {
968 size
= EVAL_CHUNKSIZE
;
969 pool
= (char*) malloc (size
);
974 switch (ch
= *Expr
++) {
976 switch (ch
= *Expr
++) {
995 if (Mtch
->s
[value
] != -1 && value
< EVAL_MATCHES
) {
996 chunklength
= Mtch
->e
[value
] - Mtch
->s
[value
];
998 newlength
= chunklength
+ length
;
999 if (newlength
> size
) {
1001 size
+= EVAL_CHUNKSIZE
;
1002 while (size
< newlength
);
1003 pool
= (char*) realloc (pool
, size
);
1004 dest
= pool
+ length
;
1007 src
= posStr
+ Mtch
->s
[value
];
1008 end
= posStr
+ Mtch
->e
[value
];
1009 if (flag
& EVAL_UPPERCASE
) {
1010 if (flag
& EVAL_LOWERCASE_NEXT
) {
1011 *dest
++ = tolower (CharAt(src
++,param
));
1012 flag
&= ~EVAL_LOWERCASE_NEXT
;
1015 *dest
++ = toupper (CharAt(src
++,param
));
1016 } else if (flag
& EVAL_LOWERCASE
) {
1017 if (flag
& EVAL_UPPERCASE_NEXT
) {
1018 *dest
++ = toupper (CharAt(src
++,param
));
1019 flag
&= ~EVAL_UPPERCASE_NEXT
;
1022 *dest
++ = tolower (CharAt(src
++,param
));
1024 if (flag
& EVAL_LOWERCASE_NEXT
) {
1025 *dest
++ = tolower (CharAt(src
++,param
));
1026 flag
&= ~EVAL_LOWERCASE_NEXT
;
1027 } else if (flag
& EVAL_UPPERCASE_NEXT
) {
1028 *dest
++ = toupper (CharAt(src
++,param
));
1029 flag
&= ~EVAL_UPPERCASE_NEXT
;
1032 *dest
++ = CharAt(src
++,param
);
1056 flag
|= EVAL_UPPERCASE
;
1059 flag
|= EVAL_UPPERCASE_NEXT
;
1062 flag
|= EVAL_LOWERCASE
;
1065 flag
|= EVAL_LOWERCASE_NEXT
;
1069 flag
&= ~(EVAL_UPPERCASE
| EVAL_LOWERCASE
);
1075 value
= toupper (*Expr
) - '0';
1077 value
= value
+ '0' - 'A' + 10;
1084 value
= toupper (*Expr
) - '0';
1086 value
= value
+ '0' - 'A' + 10;
1097 value
= toupper (*Expr
) - '0';
1104 value
= toupper (*Expr
) - '0';
1111 value
= toupper (*Expr
) - '0';
1122 value
= toupper (*Expr
) - '0';
1129 value
= toupper (*Expr
) - '0';
1136 value
= toupper (*Expr
) - '0';
1147 if (++length
> size
) {
1149 size
+= EVAL_CHUNKSIZE
;
1150 while (size
< length
);
1151 pool
= (char*) realloc (pool
, size
);
1152 dest
= pool
+ length
- 1;
1154 if (flag
& EVAL_LOWERCASE_NEXT
) {
1155 *dest
++ = tolower (ch
);
1156 flag
&= ~EVAL_LOWERCASE_NEXT
;
1157 } else if (flag
& EVAL_UPPERCASE_NEXT
) {
1158 *dest
++ = toupper (ch
);
1159 flag
&= ~EVAL_UPPERCASE_NEXT
;
1160 } else if (flag
& EVAL_UPPERCASE
)
1161 *dest
++ = toupper (ch
);
1162 else if (flag
& EVAL_LOWERCASE
)
1163 *dest
++ = tolower (ch
);
1168 if (++length
> size
) {
1170 size
+= EVAL_CHUNKSIZE
;
1171 while (size
< length
);
1172 pool
= (char*) realloc (pool
, size
);
1173 dest
= pool
+ length
- 1;