o patch and test by Andrey Gusev:

* properly replace first occurence of a pattern, resolves #10141

git-svn-id: trunk@9192 -
This commit is contained in:
florian 2007-11-11 15:54:35 +00:00
parent 72df104960
commit 05d744deb1
2 changed files with 22 additions and 2 deletions

View File

@ -1,3 +1,5 @@
{ $DEFINE DEBUG}
{
This unit implements basic regular expression support
@ -1122,7 +1124,7 @@ unit regexpr;
oldlength : PtrInt;
begin
pos:=pchar(src);
lastpos:=pos;
lastpos:=nil;
first:=true;
Result:=0;
{ estimate some length }
@ -1130,8 +1132,9 @@ unit regexpr;
while RegExprPos(RegExprEngine,pos,index,len) do
begin
inc(pos,index);
if pos>lastpos then
if (lastpos = nil) or (pos>lastpos) then
begin
if lastpos = nil then lastpos := pchar(src);
{ copy skipped part }
{ because we cheat with SetLength a SetLength(...,0) isn't what we want

View File

@ -856,5 +856,22 @@ begin
(Dest<>'asdasdasdasd') then
do_error(2009);
DestroyregExprEngine(r);
initok:=GenerateRegExprEngine('fa',[],r);
if not initok then
do_error(2000);
if (RegExprReplaceAll(r,'fasdfasdf','',Dest)<>2) or
(Dest<>'sdsdf') then
do_error(2010);
DestroyregExprEngine(r);
initok:=GenerateRegExprEngine('fa',[],r);
if not initok then
do_error(2011);
if (RegExprReplaceAll(r,'fasdfafaasdasdfafaasd','',Dest)<>5) or
(Dest<>'sdasdasdasd') then
do_error(2012);
DestroyregExprEngine(r);
writeln('*** Testing unit regexpr was successful ***');
end.