-
Notifications
You must be signed in to change notification settings - Fork 10
/
_regexp.pas
137 lines (116 loc) · 3.28 KB
/
_regexp.pas
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
131
132
133
134
135
136
137
unit _RegExp;
(******
DN/2 Plugin Interface - object model
Copyright (C) 2002 Aleksej Kozlov (Cat)
2:5030/1326.13
******)
{&Delphi+}
{&Use32+}
interface
uses
_Defines, _Objects
;
type
PRegExp = ^TRegExp;
TRegExp = object(TObject)
FStatus: TRegExpStatus;
FStart: Integer;
FLength: Integer;
constructor Init;
{destructor Done; virtual;}
procedure Reset;
function CompileString(const AExpression: String): Boolean;
function CompileStr(AExpression: PChar): Boolean;
function Compile(AExpression: PChar; ALength: Integer): Boolean;
function Execute(AString: PChar; ALength: Integer): Boolean;
function SubstituteString(ASrc: PChar; const AReplace: String;
var ADest: String): Boolean;
function SubstituteStr(ASrc, AReplace: PChar; ADest: PChar;
var ALength: Integer): Boolean;
function Substitute(ASrc, AReplace: PChar; ARLen: Integer;
ADest: PChar; var ADLen: Integer): Boolean;
procedure Error(AStatus: TRegExpStatus); virtual;
function CheckBreak: Boolean; virtual;
procedure Escape(AChar: Char; var ASubExp: PChar; var ALen: Integer)
; virtual;
private
FFlags: set of
(
ffCompiled,
ffAnchored,
ffStart,
ffParsing,
ffMatchNext,
ffBreak,
ffAutoTag
);
FCodeSize: Word;
FCodeData: PChar;
FStartP: array[1..9] of Integer;
FEndP: array[1..9] of Integer;
FStartCh: Char;
FMust: PString;
FInput: PChar;
FInputBol: PChar;
FInputEol: PChar;
FLStack: array[1..10] of Integer;
FLStackId: Integer;
end;
implementation
uses
_DNFuncs
;
constructor TRegExp.Init;
begin
_TRegExp^.Init(nil, @Self);
end;
procedure TRegExp.Reset;
begin
_TRegExp^.Reset(@Self);
end;
function TRegExp.CompileString(const AExpression: String): Boolean;
begin
Result := _TRegExp^.CompileString(AExpression, @Self);
end;
function TRegExp.CompileStr(AExpression: PChar): Boolean;
begin
Result := _TRegExp^.CompileStr(AExpression, @Self);
end;
function TRegExp.Compile(AExpression: PChar; ALength: Integer): Boolean;
begin
Result := _TRegExp^.Compile(AExpression, ALength, @Self);
end;
function TRegExp.Execute(AString: PChar; ALength: Integer): Boolean;
begin
Result := _TRegExp^.Execute(AString, ALength, @Self);
end;
function TRegExp.SubstituteString(ASrc: PChar; const AReplace: String;
var ADest: String): Boolean;
begin
Result := _TRegExp^.SubstituteString(ASrc, AReplace, ADest, @Self);
end;
function TRegExp.SubstituteStr(ASrc, AReplace: PChar; ADest: PChar;
var ALength: Integer): Boolean;
begin
Result := _TRegExp^.SubstituteStr(ASrc, AReplace, ADest, ALength, @Self);
end;
function TRegExp.Substitute(ASrc, AReplace: PChar; ARLen: Integer;
ADest: PChar; var ADLen: Integer): Boolean;
begin
Result := _TRegExp^.Substitute(ASrc, AReplace, ARLen, ADest, ADLen,
@Self);
end;
procedure TRegExp.Error(AStatus: TRegExpStatus);
assembler; {&Frame-}
asm
end;
function TRegExp.CheckBreak: Boolean;
assembler; {&Frame-}
asm
end;
procedure TRegExp.Escape(AChar: Char; var ASubExp: PChar;
var ALen: Integer);
assembler; {&Frame-}
asm
end;
end.