浏览代码

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

git-svn-id: trunk@16740 -

sergei 14 年之前
父节点
当前提交
c0f6084c2e
共有 3 个文件被更改,包括 31 次插入10 次删除
  1. 1 0
      .gitattributes
  2. 20 10
      rtl/objpas/sysutils/sysformt.inc
  3. 10 0
      tests/test/units/sysutils/tformat.pp

+ 1 - 0
.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

+ 20 - 10
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);

+ 10 - 0
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.