* AnsiReplaceText fixed, fixes 4260

git-svn-id: trunk@807 -
This commit is contained in:
florian 2005-08-07 07:57:27 +00:00
parent 287e8317a6
commit 547c3f92b2
4 changed files with 51 additions and 31 deletions

1
.gitattributes vendored
View File

@ -6158,6 +6158,7 @@ tests/webtbs/tw4233.pp svneol=native#text/plain
tests/webtbs/tw4240.pp svneol=native#text/plain
tests/webtbs/tw4247.pp svneol=native#text/plain
tests/webtbs/tw4253.pp svneol=native#text/plain
tests/webtbs/tw4260.pp svneol=native#text/plain
tests/webtbs/ub1873.pp svneol=native#text/plain
tests/webtbs/ub1883.pp svneol=native#text/plain
tests/webtbs/uw0555.pp svneol=native#text/plain

View File

@ -205,47 +205,31 @@ begin
AnsiContainsText:=AnsiPos(ASubText,AText)<>0;
end;
Function AnsiStartsText(const ASubText, AText: string): Boolean;
begin
Result:=AnsiCompareText(Copy(AText,1,Length(AsubText)),ASubText)=0;
end;
Function AnsiEndsText(const ASubText, AText: string): Boolean;
begin
result:=AnsiCompareText(Copy(AText,Length(AText)-Length(ASubText)+1,Length(ASubText)),asubtext)=0;
end;
Function AnsiReplaceText(const AText, AFromText, AToText: string): string;
var iFrom, iTo: longint;
begin
iTo:=Pos(AFromText,AText);
if iTo=0 then
result:=AText
else
begin
result:='';
iFrom:=1;
while (ito<>0) do
begin
result:=Result+Copy(AText,IFrom,Ito-IFrom+1)+AToText;
ifrom:=ITo+Length(afromtext);
ito:=Posex(Afromtext,atext,ifrom);
end;
if ifrom<=length(atext) then
result:=result+copy(AText,ifrom, length(atext));
end;
Result := StringReplace(AText,AFromText,AToText,[rfReplaceAll,rfIgnoreCase]);
end;
Function AnsiMatchText(const AText: string; const AValues: array of string): Boolean;
Function AnsiMatchText(const AText: string; const AValues: array of string): Boolean;
begin
Result:=(AnsiIndexText(AText,AValues)<>-1)
end;
Function AnsiIndexText(const AText: string; const AValues: array of string): Integer;
var i : longint;
@ -279,24 +263,19 @@ begin
end;
Function AnsiEndsStr(const ASubText, AText: string): Boolean;
begin
Result := AnsiPos(ASubText,AText)=(length(AText)-length(ASubText)+1);
end;
Function AnsiReplaceStr(const AText, AFromText, AToText: string): string;
begin
Result := StringReplace(AText,AFromText,AToText,[rfReplaceAll]);
end;
Function AnsiMatchStr(const AText: string; const AValues: array of string): Boolean;
begin
Result:=AnsiIndexStr(AText,Avalues)<>-1;
end;

View File

@ -1813,25 +1813,24 @@ begin
Dec(Result);
end;
Function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
Function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
var
Srch,OldP,RemS: string; // Srch and Oldp can contain uppercase versions of S,OldPattern
P : Integer;
begin
Srch:=S;
OldP:=OldPattern;
if rfIgnoreCase in Flags then
begin
Srch:=UpperCase(Srch);
OldP:=UpperCase(OldP);
Srch:=AnsiUpperCase(Srch);
OldP:=AnsiUpperCase(OldP);
end;
RemS:=S;
Result:='';
while (Length(Srch)<>0) do
begin
P:=Pos(OldP, Srch);
P:=AnsiPos(OldP, Srch);
if P=0 then
begin
Result:=Result+RemS;
@ -1853,6 +1852,7 @@ begin
end;
end;
Function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
begin

40
tests/webtbs/tw4260.pp Normal file
View File

@ -0,0 +1,40 @@
{ Source provided for Free Pascal Bug Report 4260 }
{ Submitted by "Rodrigo Robles" on 2005-08-07 }
{ e-mail: rodrigo_augusto_robles@yahoo.com.br }
program teste_ansireplacetext;
uses strutils;
var
str : string;
procedure docheck(const s : string);
begin
if s<>str then
halt(1);
end;
BEGIN
str:=ansireplacetext('123456789','456','ABC');
docheck('123ABC789');
str:=ansireplacetext('123456789','123','ABC');
docheck('ABC456789');
str:=ansireplacetext('123456789','789','ABC');
docheck('123456ABC');
str:=ansireplacetext('123456789','123456789','ABC');
docheck('ABC');
str:=ansireplacetext('123abc789','abc','ABC');
docheck('123ABC789');
str:=ansireplacetext('XYZ456789','xyz','ABC');
docheck('ABC456789');
str:=ansireplacetext('123456xyz','XYZ','ABC');
docheck('123456ABC');
str:=ansireplacetext('xxxxyzxxx','xxxxyzxxx','ABC');
docheck('ABC');
writeln('ok');
END.