|
@@ -1,9 +1,10 @@
|
|
var
|
|
var
|
|
OldPat,Srch: SRstring; // Srch and Oldp can contain uppercase versions of S,OldPattern
|
|
OldPat,Srch: SRstring; // Srch and Oldp can contain uppercase versions of S,OldPattern
|
|
- PatLength,NewPatLength,P,Cnt,PatCount,PrevP: Integer;
|
|
|
|
|
|
+ PatLength,NewPatLength,P,Cnt,PrevP: Integer;
|
|
c,d: SRPChar ;
|
|
c,d: SRPChar ;
|
|
|
|
|
|
begin
|
|
begin
|
|
|
|
+ aCount:=0;
|
|
Result:='';
|
|
Result:='';
|
|
c:= NIL; d:=NIL;
|
|
c:= NIL; d:=NIL;
|
|
OldPat:='';
|
|
OldPat:='';
|
|
@@ -31,6 +32,7 @@ begin
|
|
repeat
|
|
repeat
|
|
P:=Pos(OldPat,Srch,P);
|
|
P:=Pos(OldPat,Srch,P);
|
|
if P>0 then begin
|
|
if P>0 then begin
|
|
|
|
+ inc(aCount);
|
|
move(NewPattern[1],Result[P],PatLength*SizeOf(SRChar));
|
|
move(NewPattern[1],Result[P],PatLength*SizeOf(SRChar));
|
|
if not (rfReplaceAll in Flags) then exit;
|
|
if not (rfReplaceAll in Flags) then exit;
|
|
inc(P,PatLength);
|
|
inc(P,PatLength);
|
|
@@ -40,21 +42,21 @@ begin
|
|
//Different pattern length -> Result length will change
|
|
//Different pattern length -> Result length will change
|
|
//To avoid creating a lot of temporary strings, we count how many
|
|
//To avoid creating a lot of temporary strings, we count how many
|
|
//replacements we're going to make.
|
|
//replacements we're going to make.
|
|
- P:=1; PatCount:=0;
|
|
|
|
|
|
+ P:=1;
|
|
repeat
|
|
repeat
|
|
P:=Pos(OldPat,Srch,P);
|
|
P:=Pos(OldPat,Srch,P);
|
|
if P>0 then begin
|
|
if P>0 then begin
|
|
inc(P,PatLength);
|
|
inc(P,PatLength);
|
|
- inc(PatCount);
|
|
|
|
|
|
+ inc(aCount);
|
|
if not (rfReplaceAll in Flags) then break;
|
|
if not (rfReplaceAll in Flags) then break;
|
|
end;
|
|
end;
|
|
until p=0;
|
|
until p=0;
|
|
- if PatCount=0 then begin
|
|
|
|
|
|
+ if aCount=0 then begin
|
|
Result:=S;
|
|
Result:=S;
|
|
exit;
|
|
exit;
|
|
end;
|
|
end;
|
|
NewPatLength:=Length(NewPattern);
|
|
NewPatLength:=Length(NewPattern);
|
|
- SetLength(Result,Length(S)+PatCount*(NewPatLength-PatLength));
|
|
|
|
|
|
+ SetLength(Result,Length(S)+aCount*(NewPatLength-PatLength));
|
|
P:=1; PrevP:=0;
|
|
P:=1; PrevP:=0;
|
|
c:=SRPChar(Result); d:=SRPChar(S);
|
|
c:=SRPChar(Result); d:=SRPChar(S);
|
|
repeat
|
|
repeat
|