summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--generic/tclStringObj.c6
-rw-r--r--tests/format.test8
3 files changed, 17 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index bb676f8..c53d21a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-04-07 Reinhard Max <max@suse.de>
+
+ * generic/tclStringObj.c (Tcl_AppendFormatToObj):
+ Fix [format {% d}] so that it behaves the same way as in 8.4 and
+ as C's printf().
+ * tests/format.test: Add a test for '% d' and '%+d'.
+
2008-04-05 Kevin B. Kenny <kennykb@acm.org>
* tests/chanio.test (chan-io-53.9):
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 9664726..b9311ec 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -33,7 +33,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStringObj.c,v 1.70 2008/02/28 17:36:49 dgp Exp $ */
+ * RCS: @(#) $Id: tclStringObj.c,v 1.70.2.1 2008/04/07 16:07:00 dgp Exp $ */
#include "tclInt.h"
#include "tommath.h"
@@ -2003,8 +2003,8 @@ Tcl_AppendFormatToObj(
allocSegment = 1;
Tcl_IncrRefCount(segment);
- if ((isNegative || gotPlus) && (useBig || (ch == 'd'))) {
- Tcl_AppendToObj(segment, (isNegative ? "-" : "+"), 1);
+ if ((isNegative || gotPlus || gotSpace) && (useBig || (ch == 'd'))) {
+ Tcl_AppendToObj(segment, (isNegative ? "-" : gotPlus ? "+" : " "), 1);
}
if (gotHash) {
diff --git a/tests/format.test b/tests/format.test
index b050fc3..36222a5 100644
--- a/tests/format.test
+++ b/tests/format.test
@@ -10,7 +10,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: format.test,v 1.25 2008/01/10 16:09:23 dgp Exp $
+# RCS: @(#) $Id: format.test,v 1.25.2.1 2008/04/07 16:07:02 dgp Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2
@@ -496,6 +496,12 @@ test format-15.3 {testing %0..s 0 padding for chars/strings} {
test format-15.4 {testing %0..s 0 padding for chars/strings} {
format %05c 61
} {0000=}
+test format-15.5 {testing %d space padding for integers} {
+ format "(% 1d) (% 1d)" 10 -10
+} {( 10) (-10)}
+test format-15.6 {testing %d plus padding for integers} {
+ format "(%+1d) (%+1d)" 10 -10
+} {(+10) (-10)}
set a "0123456789"
set b ""