mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 18:39:19 +02:00
+ Fix for Insert and Delete functions
This commit is contained in:
parent
dbbdb79dfe
commit
0b1f401935
@ -649,26 +649,28 @@ end;
|
|||||||
|
|
||||||
Procedure Delete (Var S : AnsiString; Index,Size: Longint);
|
Procedure Delete (Var S : AnsiString; Index,Size: Longint);
|
||||||
|
|
||||||
|
Var LS : Longint;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Writeln (Index,' ',Size);
|
|
||||||
if index<=0 then
|
if index<=0 then
|
||||||
begin
|
begin
|
||||||
Size:=Size+index-1;
|
Size:=Size+index-1;
|
||||||
index:=1;
|
index:=1;
|
||||||
end;
|
end;
|
||||||
if (Index<=length(s)) and (Size>0) then
|
LS:=PAnsiRec(Pointer(S)-FirstOff)^.Len;
|
||||||
|
if (Index<=LS) and (Size>0) then
|
||||||
begin
|
begin
|
||||||
UniqueAnsiString (S);
|
UniqueAnsiString (S);
|
||||||
if Size+Index>Length(S) then
|
if Size+Index>LS then
|
||||||
Size:=Length(s)-Index+1;
|
Size:=LS-Index+1;
|
||||||
Setlength(s,Length(s)-Size);
|
if Index+Size<=LS then
|
||||||
if Index<=Length(s) then
|
begin
|
||||||
|
Dec(Index);
|
||||||
Move(PByte(Pointer(S))[Index+Size],
|
Move(PByte(Pointer(S))[Index+Size],
|
||||||
PByte(Pointer(s))[Index],Length(s)-Index+2)
|
PByte(Pointer(S))[Index],LS-Index+1);
|
||||||
else
|
end;
|
||||||
Pbyte(Pointer(S)+Length(S))^:=0;
|
Setlength(s,LS-Size);
|
||||||
end;
|
end;
|
||||||
Writeln ('Delete : Returning ',S);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
|
Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
|
||||||
@ -683,6 +685,7 @@ begin
|
|||||||
if index > LS then index := LS+1;
|
if index > LS then index := LS+1;
|
||||||
Dec(Index);
|
Dec(Index);
|
||||||
Pointer(Temp) := NewAnsiString(Length(Source)+LS);
|
Pointer(Temp) := NewAnsiString(Length(Source)+LS);
|
||||||
|
SetLength(Temp,Length(Source)+LS);
|
||||||
If Index>0 then
|
If Index>0 then
|
||||||
move (Pointer(S)^,Pointer(Temp)^,Index);
|
move (Pointer(S)^,Pointer(Temp)^,Index);
|
||||||
Move (Pointer(Source)^,PByte(Temp)[Index],Length(Source));
|
Move (Pointer(Source)^,PByte(Temp)[Index],Length(Source));
|
||||||
@ -694,7 +697,10 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.31 1998-11-13 14:37:11 michael
|
Revision 1.32 1998-11-16 11:11:47 michael
|
||||||
|
+ Fix for Insert and Delete functions
|
||||||
|
|
||||||
|
Revision 1.31 1998/11/13 14:37:11 michael
|
||||||
+ Insert procedure corrected
|
+ Insert procedure corrected
|
||||||
|
|
||||||
Revision 1.30 1998/11/05 14:20:36 peter
|
Revision 1.30 1998/11/05 14:20:36 peter
|
||||||
|
Loading…
Reference in New Issue
Block a user