mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 16:49:20 +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
|
This unit implements basic regular expression support
|
||||||
|
|
||||||
@ -1122,7 +1124,7 @@ unit regexpr;
|
|||||||
oldlength : PtrInt;
|
oldlength : PtrInt;
|
||||||
begin
|
begin
|
||||||
pos:=pchar(src);
|
pos:=pchar(src);
|
||||||
lastpos:=pos;
|
lastpos:=nil;
|
||||||
first:=true;
|
first:=true;
|
||||||
Result:=0;
|
Result:=0;
|
||||||
{ estimate some length }
|
{ estimate some length }
|
||||||
@ -1130,8 +1132,9 @@ unit regexpr;
|
|||||||
while RegExprPos(RegExprEngine,pos,index,len) do
|
while RegExprPos(RegExprEngine,pos,index,len) do
|
||||||
begin
|
begin
|
||||||
inc(pos,index);
|
inc(pos,index);
|
||||||
if pos>lastpos then
|
if (lastpos = nil) or (pos>lastpos) then
|
||||||
begin
|
begin
|
||||||
|
if lastpos = nil then lastpos := pchar(src);
|
||||||
{ copy skipped part }
|
{ copy skipped part }
|
||||||
|
|
||||||
{ because we cheat with SetLength a SetLength(...,0) isn't what we want
|
{ because we cheat with SetLength a SetLength(...,0) isn't what we want
|
||||||
|
@ -856,5 +856,22 @@ begin
|
|||||||
(Dest<>'asdasdasdasd') then
|
(Dest<>'asdasdasdasd') then
|
||||||
do_error(2009);
|
do_error(2009);
|
||||||
DestroyregExprEngine(r);
|
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 ***');
|
writeln('*** Testing unit regexpr was successful ***');
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user