mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-18 17:19:32 +02:00
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:
parent
72df104960
commit
05d744deb1
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user