summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgriffin <brian_griffin@mentor.com>2017-06-12 14:04:29 (GMT)
committergriffin <brian_griffin@mentor.com>2017-06-12 14:04:29 (GMT)
commit78e17f7f0cce0233cc1009b3f7c3aa2ea32763d7 (patch)
tree2a4e1d63e9c5c5feedcb6f21d5a637f95403b93b
parent7ad256b22a418232031230af7c60a0e21e979df6 (diff)
downloadtcl-78e17f7f0cce0233cc1009b3f7c3aa2ea32763d7.zip
tcl-78e17f7f0cce0233cc1009b3f7c3aa2ea32763d7.tar.gz
tcl-78e17f7f0cce0233cc1009b3f7c3aa2ea32763d7.tar.bz2
Add support of 0d in the format %# conversion flag. Add tests for same.
-rw-r--r--doc/format.n16
-rw-r--r--generic/tclStringObj.c4
-rw-r--r--tests/format.test19
3 files changed, 32 insertions, 7 deletions
diff --git a/doc/format.n b/doc/format.n
index ba044f2..a386464 100644
--- a/doc/format.n
+++ b/doc/format.n
@@ -83,14 +83,16 @@ Specifies that the number should be padded on the left with
zeroes instead of spaces.
.TP 10
\fB#\fR
-Requests an alternate output form. For \fBo\fR and \fBO\fR
-conversions it guarantees that the first digit is always \fB0\fR.
-For \fBx\fR or \fBX\fR conversions, \fB0x\fR or \fB0X\fR (respectively)
-will be added to the beginning of the result unless it is zero.
+Requests an alternate output form. For \fBo\fR and \fBO\fR
+conversions it guarantees that the first digit is always \fB0\fR.
+For \fBx\fR or \fBX\fR conversions, \fB0x\fR or \fB0X\fR (respectively)
+will be added to the beginning of the result unless it is zero.
For \fBb\fR conversions, \fB0b\fR
-will be added to the beginning of the result unless it is zero.
-For all floating-point conversions (\fBe\fR, \fBE\fR, \fBf\fR,
-\fBg\fR, and \fBG\fR) it guarantees that the result always
+will be added to the beginning of the result unless it is zero.
+For \fBd\fR conversions, \fB0d\fR will be added to the beginning
+of the result unless it is zero.
+For all floating-point conversions (\fBe\fR, \fBE\fR, \fBf\fR,
+\fBg\fR, and \fBG\fR) it guarantees that the result always
has a decimal point.
For \fBg\fR and \fBG\fR conversions it specifies that
trailing zeroes should not be removed.
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 7c898b7..3a6e60e 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -2039,6 +2039,10 @@ Tcl_AppendFormatToObj(
Tcl_AppendToObj(segment, "0b", 2);
segmentLimit -= 2;
break;
+ case 'd':
+ Tcl_AppendToObj(segment, "0d", 2);
+ segmentLimit -= 2;
+ break;
}
}
diff --git a/tests/format.test b/tests/format.test
index 722ad21..577365b 100644
--- a/tests/format.test
+++ b/tests/format.test
@@ -79,6 +79,25 @@ test format-1.11.1 {integer formatting} longIs64bit {
test format-1.12 {integer formatting} {
format "%b %#b %#b %llb" 5 0 5 [expr {2**100}]
} {101 0b0 0b101 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000}
+test format-1.13 {integer formatting} longIs32bit {
+ format "%#d %#d %#d %#d %#d" 0 6 34 16923 -12 -1
+} {0d0 0d6 0d34 0d16923 -0d12}
+test format-1.13.1 {integer formatting} longIs64bit {
+ format "%#d %#d %#d %#d %#d" 0 6 34 16923 -12 -1
+} {0d0 0d6 0d34 0d16923 -0d12}
+test format-1.14 {integer formatting} longIs32bit {
+ format "%#5d %#20d %#20d %#20d %#20d" 0 6 34 16923 -12 -1
+} { 0d0 0d6 0d34 0d16923 -0d12}
+test format-1.14.1 {integer formatting} longIs64bit {
+ format "%#5d %#20d %#20d %#20d %#20d" 0 6 34 16923 -12 -1
+} { 0d0 0d6 0d34 0d16923 -0d12}
+test format-1.15 {integer formatting} longIs32bit {
+ format "%-#5d %-#20d %-#20d %-#20d %-#20d" 0 6 34 16923 -12 -1
+} {0d0 0d6 0d34 0d16923 -0d12 }
+test format-1.15.1 {integer formatting} longIs64bit {
+ format "%-#5d %-#20d %-#20d %-#20d %-#20d" 0 6 34 16923 -12 -1
+} {0d0 0d6 0d34 0d16923 -0d12 }
+
test format-2.1 {string formatting} {
format "%s %s %c %s" abcd {This is a very long test string.} 120 x