📄 cregexp.cpp
字号:
case ReNDigit: for (k = 0x30;k < 0x40;k++) if (!IsDigit((char)k)) Next->un.ChrClass->SetBit(k); break; case ReWordSymb: for (k = 0;k < 256;k++) if (IsWord((char)k)) Next->un.ChrClass->SetBit(k); break; case ReNWordSymb: for (k = 0;k < 256;k++) if (!IsWord((char)k)) Next->un.ChrClass->SetBit(k); break; case ReWSpace: Next->un.ChrClass->SetBit(0x20); // tab also! Next->un.ChrClass->SetBit(0x9); break; case ReNWSpace: for(k = 0; k < 8; k++) Next->un.ChrClass->IArr[k] = 0xFFFFFFFF; Next->un.ChrClass->ClearBit(0x20); Next->un.ChrClass->ClearBit(0x9); break; default: if (!(Exprn[j]&0xFF00)) Next->un.ChrClass->SetBit(Exprn[j]&0xFF); break; }; }; Add = true; i=j; }; // ( ... ) if (Exprn[i] == ReLBrack){ EnterBr = 1; for (j = i+1;j < end;j++){ if (Exprn[j] == ReLBrack) EnterBr++; if (Exprn[j] == ReRBrack) EnterBr--; if (!EnterBr) break; }; if (EnterBr) return EBRACKETS; Next->Op = ReBrackets; Next->un.Param = new SRegInfo; Next->un.Param->Parent = Next; Next->s = CurMatch++; if (CurMatch > MATCHESNUM) CurMatch = MATCHESNUM; EError er = SetStructs(Next->un.Param,i+1,j); if (er) return er; Add = true; i = j; }; if ((Exprn[i]&0xFF00) == ReBkTrace){ Next->Op = ReBkTrace; Next->un.Symb = Exprn[i]&0xFF; Add = true; }; if ((Exprn[i]&0xFF00) == ReBkBrack){ Next->Op = ReBkBrack; Next->un.Symb = Exprn[i]&0xFF; Add = true; }; if ((Exprn[i]&0xFF00) == ReBehind){ Next->Op = ReBehind; Next->s = Exprn[i]&0xFF; Add = true; }; if ((Exprn[i]&0xFF00) == ReNBehind){ Next->Op = ReNBehind; Next->s = Exprn[i]&0xFF; Add = true; }; // Chars if (Exprn[i] >= ReAnyChr && Exprn[i] < ReTemp || Exprn[i] < 0x100){ Next->Op = ReSymb; Next->un.Symb = Exprn[i]; Add = true; }; // Next if (Add && i != end-1){ Next->Next = new SRegInfo; Next->Next->Parent = Next->Parent; Next = Next->Next; }; }; Next = re; Prev = Prev2 = 0; while(Next){ if (Next->Op > ReBlockOps && Next->Op < ReSymbolOps){ if (!Prev) return EOP; if (!Prev2) re = Next; else Prev2->Next = Next; //if (Prev->Op > ReBlockOps && Prev->Op < ReSymbolOps) return false; Prev->Parent = Next; Prev->Next = 0; Next->un.Param = Prev; Prev = Prev2; }; Prev2 = Prev; Prev = Next; Next = Next->Next; }; return EOK;};////////////////////////////////////////////////////////////////////////////// parsingbool CRegExp::CheckSymb(int Symb, bool Inc){bool Res; switch(Symb){ case ReAnyChr: if (toParse >= End) return false; if (Inc) toParse++; return true; case ReSoL: return (Start == toParse); case ReEoL: return (End == toParse); case ReDigit: if (toParse >= End) return false; Res = IsDigit(cptrans(*toParse)); if (Res && Inc) toParse++; return Res; case ReNDigit: if (toParse >= End) return false; Res = !IsDigit(cptrans(*toParse)); if (Res && Inc) toParse++; return Res; case ReWordSymb: if (toParse >= End) return false; Res = IsWord(cptrans(*toParse)); if (Res && Inc) toParse++; return Res; case ReNWordSymb: if (toParse >= End) return false; Res = !IsWord(cptrans(*toParse)); if (Res && Inc) toParse++; return Res; case ReWSpace: if (toParse >= End) return false; Res = (*toParse == 0x20 || *toParse == '\t'); if (Res && Inc) toParse++; return Res; case ReNWSpace: if (toParse >= End) return false; Res = !(*toParse == 0x20 || *toParse == '\t'); if (Res && Inc) toParse++; return Res; case ReUCase: if (toParse >= End) return false; Res = IsUpperCase(cptrans(*toParse)); if (Res && Inc) toParse++; return Res; case ReNUCase: if (toParse >= End) return false; Res = IsLowerCase(cptrans(*toParse)); if (Res && Inc) toParse++; return Res; case ReWBound: if (toParse >= End) return true; return IsWord(cptrans(*toParse)) && (toParse == Start || !IsWord(cptrans(*(toParse - 1)))); case ReNWBound: if (toParse >= End) return true; return !IsWord(cptrans(*toParse)) && IsWord(cptrans(*(toParse-1))); case RePreNW: if (toParse >= End) return true; return (toParse == Start || !IsWord(cptrans(*(toParse-1)))); case ReStart: Matches->s[0] = (toParse - Start); return true; case ReEnd: Matches->e[0] = (toParse - Start); return true; default: if ((Symb & 0xFF00) || toParse >= End) return false; if (NoCase){ if (LowCase(cptrans(*toParse)) != LowCase(cptrans((char)Symb&0xFF))) return false; }else if (*toParse != (char)(Symb&0xFF)) return false; if (Inc) toParse++; return true; };}bool CRegExp::LowParseRe(PRegInfo &Next){PRegInfo OrNext;int i,match,sv;char *tStr; switch(Next->Op){ case ReSymb: if (!CheckSymb(Next->un.Symb,true)) return false; break; case ReEmpty: break; case ReBkTrace: if (!bkstr | !bktrace) return false; sv = Next->un.Symb; tStr = toParse; for (i = bktrace->s[sv]; i < bktrace->e[sv]; i++){ if (*tStr != bkstr[i] || End == tStr) return false; tStr++; }; toParse = tStr; break; case ReBkBrack: sv = Next->un.Symb; tStr = toParse; if (Matches->s[sv] == -1 || Matches->e[sv] == -1) return false; for (i = Matches->s[sv]; i < Matches->e[sv]; i++){ if (*tStr != Start[i] || End == tStr) return false; tStr++; }; toParse = tStr; break; case ReBehind: sv = Next->s; tStr = toParse; toParse -= sv; if (!LowParse(Next->un.Param)) return false; toParse = tStr; break; case ReNBehind: sv = Next->s; tStr = toParse; toParse -= sv; if (LowParse(Next->un.Param)) return false; toParse = tStr; break; case ReAhead: tStr = toParse; if (!LowParse(Next->un.Param)) return false; toParse = tStr; break; case ReNAhead: tStr = toParse; if (LowParse(Next->un.Param)) return false; toParse = tStr; break; case ReEnum: if (toParse >= End) return false; if (!Next->un.ChrClass->GetBit(*toParse)) return false; toParse++; break; case ReNEnum: if (toParse >= End) return false; if (Next->un.ChrClass->GetBit(*toParse)) return false; toParse++; break; case ReBrackets: match = Next->s; sv = toParse-Start; tStr = toParse; if (LowParse(Next->un.Param)){ if (match < MATCHESNUM && (match || (Matches->s[match] == -1))) Matches->s[match] = sv; if (match < MATCHESNUM && (match || (Matches->e[match] == -1))) Matches->e[match] = toParse-Start; return true; }; toParse = tStr; return false; case ReMul: tStr = toParse; while (LowParse(Next->un.Param)); while(!LowCheckNext(Next) && tStr < toParse) toParse--; break; case ReNGMul: do{ if (LowCheckNext(Next)) break; }while (LowParse(Next->un.Param)); break; case RePlus: tStr = toParse; match = false; while (LowParse(Next->un.Param)) match = true; if (!match) return false; while(!LowCheckNext(Next) && tStr < toParse) toParse--; break; case ReNGPlus: if (!LowParse(Next->un.Param)) return false; do{ if (LowCheckNext(Next)) break; }while (LowParse(Next->un.Param)); break; case ReQuest: LowParse(Next->un.Param); break; case ReNGQuest: if (LowCheckNext(Next)) break; if (!LowParse(Next->un.Param)) return false; break; case ReOr: OrNext = Next; // tStr = toParse; if (LowParse(Next->un.Param)){ while (OrNext && OrNext->Op == ReOr) OrNext = OrNext->Next; /*if (!LowCheckNext(OrNext)){ toParse = tStr; OrNext = Next; };*/ }; Next = OrNext; break; case ReRangeN: tStr = toParse; i = 0; while (LowParse(Next->un.Param)) i++; do{ if (i < Next->s){ toParse = tStr; return false; }; i--; }while(!LowCheckNext(Next) && tStr < toParse--); break; case ReNGRangeN: tStr = toParse; i = 0; while (LowParse(Next->un.Param)){ i++; if (i >= Next->s && LowCheckNext(Next)) break; }; if (i < Next->s){ toParse = tStr; return false; }; break; case ReRangeNM: tStr = toParse; i = 0; while (i < Next->s && LowParse(Next->un.Param)) i++; if (i < Next->s){ toParse = tStr; return false; }; while (i < Next->e && LowParse(Next->un.Param)) i++; while(!LowCheckNext(Next)){ i--; toParse--; if (i < Next->s){ toParse = tStr; return false; }; }; break; case ReNGRangeNM: tStr = toParse; i = 0; while (i < Next->s && LowParse(Next->un.Param)) i++; if (i < Next->s){ toParse = tStr; return false; }; while(!LowCheckNext(Next)){ i++; if (!LowParse(Next->un.Param) || i > Next->e){ toParse = tStr; return false; }; }; break; }; return true;};bool CRegExp::LowCheckNext(PRegInfo Re){PRegInfo Next;char *tmp = toParse;Next = Re; do{ if (Next && Next->Op == ReOr) while (Next && Next->Op == ReOr) Next = Next->Next; if (Next->Next && !LowParse(Next->Next)){ toParse = tmp;// Ok = false; return false; }; Next = Next->Parent; }while(Next); toParse = tmp;// if (Ok != false) Ok = true; return true;};bool CRegExp::LowParse(PRegInfo Re){ while(Re && toParse <= End){ if (!LowParseRe(Re)) return false; if (Re) Re = Re->Next; }; return true;};bool CRegExp::QuickCheck(){ if (!NoMoves || !FirstChar) return true; switch(FirstChar){ case ReSoL: if (toParse != Start) return false; return true; case ReWBound: return IsWord(cptrans(*toParse)) && (toParse == Start || !IsWord(cptrans(*(toParse-1)))); default: if (NoCase && LowCase(cptrans(*toParse)) != LowCase(cptrans(FirstChar))) return false; if (!NoCase && *toParse != (char)FirstChar) return false; return true; };};bool CRegExp::ParseRe(char *Str){ if (Error) return false; toParse = Str; if (!QuickCheck()) return false; for (int i = 0; i < MATCHESNUM; i++) Matches->s[i] = Matches->e[i] = -1; Matches->CurMatch = CurMatch;// Ok = -1; do{ if (!LowParse(Info)){ if (NoMoves) return false; }else return true; toParse = ++Str; }while(toParse != End+1); return false;};bool CRegExp::Parse(char *Str,char *Sol, char *Eol, PMatches Mtch, int Moves){ if (!this) return false; bool s = NoMoves; if (Moves != -1) NoMoves = Moves!=0; Start = Sol; End = Eol; Matches = Mtch; bool r = ParseRe(Str); NoMoves = s; return r;};bool CRegExp::Parse(char *Str, PMatches Mtch){ if (!this) return false; End = Start = Str; while(*End) End++; Matches = Mtch; return ParseRe(Str);};bool CRegExp::SetNoMoves(bool Moves){ NoMoves = Moves; return true;};bool CRegExp::SetBkTrace(char *str, PMatches trace){ bktrace = trace; bkstr = str; return true;};bool CRegExp::GetBkTrace(char **str, PMatches *trace){ *str = bkstr; *trace = bktrace; return true;};char inline CRegExp::cptrans(char c){ return CodePage?CodePage[(unsigned char)c]:c;};void CRegExp::SetCodePage(char* Table){ CodePage = Table;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -