* SysUtils.Format: Fixed behavior in case when format specifier contains both index and '*' for width/precision.

+ test

git-svn-id: trunk@16740 -
This commit is contained in:
sergei 2011-01-08 20:08:16 +00:00
parent a03c7cdc69
commit c0f6084c2e
3 changed files with 31 additions and 10 deletions

1
.gitattributes vendored
View File

@ -9959,6 +9959,7 @@ tests/test/units/sysutils/tfile1.pp svneol=native#text/plain
tests/test/units/sysutils/tfile2.pp svneol=native#text/plain
tests/test/units/sysutils/tfilename.pp svneol=native#text/plain
tests/test/units/sysutils/tfloattostr.pp svneol=native#text/plain
tests/test/units/sysutils/tformat.pp svneol=native#text/plain
tests/test/units/sysutils/tlocale.pp svneol=native#text/plain
tests/test/units/sysutils/trwsync.pp svneol=native#text/plain
tests/test/units/sysutils/tsscanf.pp svneol=native#text/plain

View File

@ -19,8 +19,9 @@ Var ChPos,OldPos,ArgPos,DoArg,Len : SizeInt;
Procedure ReadInteger;
var Code: Word;
var
Code: Word;
ArgN: SizeInt;
begin
If Value<>-1 then exit; // Was already read.
OldPos:=ChPos;
@ -30,16 +31,27 @@ Var ChPos,OldPos,ArgPos,DoArg,Len : SizeInt;
DoFormatError(feInvalidFormat);
If Fmt[ChPos]='*' then
begin
If (ChPos>OldPos) or (ArgPos>High(Args)) then
if Index=-1 then
ArgN:=Argpos
else
begin
ArgN:=Index;
Inc(Index);
end;
If (ChPos>OldPos) or (ArgN>High(Args)) then
DoFormatError(feInvalidFormat);
case Args[ArgPos].Vtype of
vtInteger: Value := Args[ArgPos].VInteger;
vtInt64: Value := Args[ArgPos].VInt64^;
vtQWord: Value := Args[ArgPos].VQWord^;
ArgPos:=ArgN+1;
case Args[ArgN].Vtype of
vtInteger: Value := Args[ArgN].VInteger;
vtInt64: Value := Args[ArgN].VInt64^;
vtQWord: Value := Args[ArgN].VQWord^;
else
DoFormatError(feInvalidFormat);
end;
Inc(ArgPos);
Inc(ChPos);
end
else
@ -197,8 +209,6 @@ begin
result:=true;
end;
Const Zero = '000000000000000000000000000000000000000000000000000000000000000';
begin
Result:='';
Len:=Length(Fmt);

View File

@ -0,0 +1,10 @@
uses sysutils;
begin
if format('>%1:*s<',[0, 12,'def',-15]) <> '> def<' then
Halt(1);
if format('>%1:*s< >%*s<', [0, 12, 'abc', 10, 'def']) <> '> abc< > def<' then
Halt(2);
if format('>%1:*.*s< >%*.*s<', [0, 10,10,'abc', 6,6,'def']) <> '> abc< > def<' then
Halt(3);
end.