From c0f6084c2ec91b311577d95508f48d657d7725b3 Mon Sep 17 00:00:00 2001 From: sergei Date: Sat, 8 Jan 2011 20:08:16 +0000 Subject: [PATCH] * SysUtils.Format: Fixed behavior in case when format specifier contains both index and '*' for width/precision. + test git-svn-id: trunk@16740 - --- .gitattributes | 1 + rtl/objpas/sysutils/sysformt.inc | 30 ++++++++++++++++++---------- tests/test/units/sysutils/tformat.pp | 10 ++++++++++ 3 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 tests/test/units/sysutils/tformat.pp diff --git a/.gitattributes b/.gitattributes index 719c3417b1..e9b73a95af 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/rtl/objpas/sysutils/sysformt.inc b/rtl/objpas/sysutils/sysformt.inc index 1ea54370f6..367e8a5cf5 100644 --- a/rtl/objpas/sysutils/sysformt.inc +++ b/rtl/objpas/sysutils/sysformt.inc @@ -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); diff --git a/tests/test/units/sysutils/tformat.pp b/tests/test/units/sysutils/tformat.pp new file mode 100644 index 0000000000..a7da6c88a9 --- /dev/null +++ b/tests/test/units/sysutils/tformat.pp @@ -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. \ No newline at end of file