3 //=====================================================================
4 // BRegExp.pas : Borland Delphi
\97p BREGEXP.DLL
\97\98\97p
\83\86\83j
\83b
\83g
5 // 1998/10/11
\94Å osamu@big.or.jp
7 // BREGEXP.DLL
\82Í
\81Ahttp://www.hi-ho.or.jp/~babaq/
\82É
\82Ä
\8cö
\8aJ
\82³
\82ê
\82Ä
\82¢
\82é
8 // Perl5
\8cÝ
\8a·
\82Ì
\90³
\8bK
\95\
\8c»
\83G
\83\93\83W
\83\93 BREGEXP.DLL
\82ð Borland Delphi
\82©
\82ç
\97\98\97p
9 //
\82·
\82é
\82½
\82ß
\82Ì
\83\86\83j
\83b
\83g
\83t
\83@
\83C
\83\8b\82Å
\82·
\81BDelphi 3
\82Å
\8dì
\90¬
\82µ
\82Ü
\82µ
\82½
\82ª
\81A32bit
10 //
\94Å
\82Ì Delphi
\82¨
\82æ
\82Ñ C++ Builder
\82Å
\93®
\8dì
\89Â
\94\
\82Æ
\8ev
\82¢
\82Ü
\82·
\81B
12 // BREGEXP.DLL
\82Ì
\97\98\97p
\8fð
\8c\8f\82È
\82Ç
\82Í
\81A
\93¯
\83z
\81[
\83\80\83y
\81[
\83W
\82ð
\82²
\8eQ
\8fÆ
\89º
\82³
\82¢
\81B
\97L
\97p
\82È
13 //
\83\89\83C
\83u
\83\89\83\8a\82ð
\96³
\8f\9e\82Å
\92ñ
\8b\9f\89º
\82³
\82Á
\82Ä
\82¢
\82é babaq
\82³
\82ñ
\82É
\8a´
\8eÓ
\82·
\82é
\82Æ
\82Æ
\82à
\82É
\81A
14 //
\8d¡
\8cã
\82Ì
\82²
\8a\88\96ô
\82ð
\8aú
\91Ò
\82µ
\82Ä
\82¢
\82Ü
\82·
\81B
16 //
\96{
\83\86\83j
\83b
\83g
\82Ì
\92\98\8dì
\8c \82É
\82Â
\82¢
\82Ä
\82Í
\81A
\82Æ
\82â
\82©
\82
\8c¾
\82¤
\82Â
\82à
\82è
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\81B
\8dD
\82«
\82È
17 //
\82æ
\82¤
\82É
\82¨
\8eg
\82¢
\89º
\82³
\82¢
\81B
\82½
\82¾
\82µ
\81A
\97\98\97p
\82É
\93\96\82½
\82Á
\82Ä
\82Í
\82²
\8e©
\95ª
\82Ì
\90Ó
\94C
\82Ì
\89º
\82É
\82¨
\8aè
18 //
\82¢
\82µ
\82Ü
\82·
\81B
\96{
\83\86\83j
\83b
\83g
\82É
\8aÖ
\82µ
\82Ä osamu@big.or.jp
\82Í
\89½
\82ç
\90Ó
\94C
\82ð
\95\89\82¤
\82±
\82Æ
\82Í
19 //
\96³
\82¢
\82à
\82Ì
\82Æ
\82µ
\82Ü
\82·
\81B
21 //
\96{
\83\86\83j
\83b
\83g
\82Í
\81A DLL
\82Æ
\82Æ
\82à
\82É
\94z
\95z
\82³
\82ê
\82Ä
\82¢
\82é
\83w
\83b
\83_
\83t
\83@
\83C
\83\8b\8by
\82Ñ
\81A
\8fã
\8bL
\83z
\81[
\83\80
22 //
\83y
\81[
\83W
\82Å
\8ds
\82í
\82ê
\82½
\83\86\81[
\83U
\83T
\83|
\81[
\83g
\82Ì
\83\8d\83O
\83t
\83@
\83C
\83\8b\82ð
\82à
\82Æ
\82É
\8dì
\90¬
\82³
\82ê
\82Ü
\82µ
\82½
\81B
23 //
\82¨
\8bC
\82Ã
\82«
\82Ì
\93_
\82È
\82Ç
\82 \82è
\82Ü
\82µ
\82½
\82ç
\81Aosamu@big.or.jp
\82Ü
\82Å
\93d
\8eq
\83\81\81[
\83\8b\82É
\82Ä
24 //
\82¨
\92m
\82ç
\82¹
\89º
\82³
\82ê
\82Î
\81A
\8bC
\95ª
\8e\9f\91æ
\82Å
\82Í
\82È
\82ñ
\82ç
\82©
\82Ì
\91Î
\8f\88\82ð
\82·
\82é
\89Â
\94\
\90«
\82ª
\82 \82è
\82Ü
\82·
\81B(^_^;
26 //
\8eg
\97p
\95û
\96@
\82É
\82Â
\82¢
\82Ä
\82Í
\95t
\91®
\82Ì
\83w
\83\8b\83v
\83t
\83@
\83C
\83\8b\82ð
\82²
\97\97\89º
\82³
\82¢
\81B
29 // 98.10.3
\8f\89\8aú
\83o
\81[
\83W
\83\87\83\93
30 // 98.10.11
\83o
\83O
\83t
\83B
\83b
\83N
\83X (TBRegExpRec.splitp
\82ð ^PChar -> PPChar)
32 //=====================================================================
38 //=====================================================================
39 //
\96{
\89Æ BREGEXP.H
\82Æ
\81A
\83T
\83|
\81[
\83g
\83z
\81[
\83\80\83y
\81[
\83W
\82Ì
\83h
\83L
\83\85\83\81\83\93\83g
\82æ
\82è
40 // BREGEXP.DLL
\82Æ
\92¼
\8c\8b\82µ
\82½
\90é
\8c¾
41 //=====================================================================
46 outp: PChar; //
\92u
\8a·
\82¦
\8c\8b\89Ê
\90æ
\93ª
\83|
\83C
\83\93\83^
47 outendp: PChar; //
\92u
\8a·
\82¦
\8c\8b\89Ê
\96\96\94ö
\83|
\83C
\83\93\83^
48 splitctr: Integer; // split
\8c\8b\89Ê
\83J
\83E
\83\93\83^
49 splitp: PPChar; // split
\8c\8b\89Ê
\83|
\83C
\83\93\83^
\83|
\83C
\83\93\83^
50 rsv1: Integer; //
\97\
\96ñ
\8dÏ
\82Ý
51 parap: PChar; //
\83R
\83}
\83\93\83h
\95¶
\8e\9a\97ñ
\90æ
\93ª
\83|
\83C
\83\93\83^ ('s/xxxxx/yy/gi')
52 paraendp: PChar; //
\83R
\83}
\83\93\83h
\95¶
\8e\9a\97ñ
\96\96\94ö
\83|
\83C
\83\93\83^
53 transtblp: PChar; // tr
\83e
\81[
\83u
\83\8b\82Ö
\82Ì
\83|
\83C
\83\93\83^
54 startp: PPChar; //
\83}
\83b
\83`
\82µ
\82½
\95¶
\8e\9a\97ñ
\82Ö
\82Ì
\90æ
\93ª
\83|
\83C
\83\93\83^
55 endp: PPChar; //
\83}
\83b
\83`
\82µ
\82½
\95¶
\8e\9a\97ñ
\82Ö
\82Ì
\96\96\94ö
\83|
\83C
\83\93\83^
57 pTBRegExpRec=^TBRegExpRec;
59 function BMatch(str, target, targetendp: PChar;
60 var rxp: pTBRegExpRec; msg: PChar): Boolean; cdecl;
61 external 'bregexp.dll';
62 function BSubst(str, target, targetendp: PChar;
63 var rxp: pTBRegExpRec; msg: PChar): Boolean; cdecl;
64 external 'bregexp.dll';
65 function BTrans(str, target, targetendp: PChar;
66 var rxp: pTBRegExpRec; msg: PChar): Boolean; cdecl;
67 external 'bregexp.dll';
68 function BSplit(str, target, targetendp: PChar; limit: Integer;
69 var rxp: pTBRegExpRec; msg: PChar): Boolean; cdecl;
70 external 'bregexp.dll';
71 procedure BRegFree(rx: pTBRegExpRec); cdecl;
72 external 'bregexp.dll' name 'BRegfree';
73 function BRegExpVersion: PChar; cdecl;
74 external 'bregexp.dll' name 'BRegexpVersion';
76 //=====================================================================
77 // TBRegExp : BREGEXP.DLL
\82Ì
\8b@
\94\
\82ð
\83J
\83v
\83Z
\83\8b\89»
\82·
\82é
\83I
\83u
\83W
\83F
\83N
\83g
78 //=====================================================================
81 EBRegExpError=class(Exception) end;
82 TBRegExpMode=(brxNone, brxMatch, brxSplit);
83 TBRegExp=class(TObject)
86 pBRegExp: PTBRegExpRec;
87 function GetSplitCount: Integer;
88 function GetSplitStrings(index: Integer): string;
89 function GetMatchStrings(index:Integer): string;
90 function GetMatchCount: Integer;
91 function GetCount: Integer;
92 function GetStrings(index: Integer): string;
94 destructor Destroy; override;
96 function Match(const Command, TargetString: string): Boolean;
97 function Subst(const Command: string;var TargetString: string): Boolean;
98 function Split(const Command, TargetString: string; Limit: Integer): Boolean;
99 function Trans(const Command: string;var TargetString: string): Boolean;
100 property Count: Integer read GetCount;
101 property Strings[index: Integer]: string read GetStrings; default;
104 //=====================================================================
108 //=====================================================================
110 destructor TBRegExp.Destroy;
112 if pBRegExp<>nil then
117 //=====================================================================
119 function TBRegExp.Match(const Command, TargetString: string): Boolean;
120 var ErrorString: string;
122 SetLength(ErrorString,256);
127 PChar(TargetString)+Length(TargetString),
130 SetLength(ErrorString,StrLen(PChar(ErrorString)));
131 if ErrorString<>'' then
132 raise EBRegExpError.Create(ErrorString);
136 //=====================================================================
138 function TBRegExp.Subst(const Command: string;
139 var TargetString: string): Boolean;
140 var ErrorString: string;
142 SetLength(ErrorString,256);
147 PChar(TargetString)+Length(TargetString),
150 SetLength(ErrorString,StrLen(PChar(ErrorString)));
151 if ErrorString<>'' then
152 raise EBRegExpError.Create(ErrorString);
153 if Result then TargetString:=pBRegExp^.outp;
156 //=====================================================================
158 function TBRegExp.Trans(const Command: string;
159 var TargetString: string): Boolean;
160 var ErrorString: string;
162 SetLength(ErrorString,256);
167 PChar(TargetString)+Length(TargetString),
170 SetLength(ErrorString,StrLen(PChar(ErrorString)));
171 if ErrorString<>'' then
172 raise EBRegExpError.Create(ErrorString);
173 if Result then TargetString:=pBRegExp^.outp;
176 //=====================================================================
178 function TBRegExp.Split(const Command, TargetString: string;
179 Limit: Integer): Boolean;
180 var ErrorString: string;
182 SetLength(ErrorString,256);
187 PChar(TargetString)+Length(TargetString),
191 SetLength(ErrorString,StrLen(PChar(ErrorString)));
192 if ErrorString<>'' then
193 raise EBRegExpError.Create(ErrorString);
197 //=====================================================================
199 function TBRegExp.GetCount: Integer;
204 raise EBRegExpError.Create('no count now');
206 Result:=GetMatchCount;
208 Result:=GetSplitCount;
212 function TBRegExp.GetMatchCount: Integer;
216 sp:=pBRegExp^.startp;
218 while Integer(sp^)<Integer(ep^) do begin
225 function TBRegExp.GetSplitCount: Integer;
227 Result:=pBRegExp^.splitctr;
230 //=====================================================================
232 function TBRegExp.GetStrings(index: Integer): string;
237 raise EBRegExpError.Create('no strings now');
239 Result:=GetMatchStrings(index);
241 Result:=GetSplitStrings(index);
245 function TBRegExp.GetMatchStrings(index:Integer):string;
249 sp:=pBRegExp^.startp;
251 while index>0 do begin
252 if Integer(sp^)>=Integer(ep^) then
253 raise EBRegExpError.Create('index out of range');
258 SetLength(Result,Integer(ep^)-Integer(sp^));
259 Move(sp^^,PChar(Result)^,Integer(ep^)-Integer(sp^));
262 function TBRegExp.GetSplitStrings(index:Integer): string;
266 if (index<0) or (index>=GetSplitCount) then
267 raise EBRegExpError.Create('index out of range');
273 SetLength(Result,Integer(ep)-Integer(sp));
274 Move(sp^,PChar(Result)^,Integer(ep)-Integer(sp));
277 //=====================================================================