Tcl Source Code

Check-in [20eeb7733d]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Little variation on Brian's proposal: Only prefix decimal number with '0d' when that's necessary for correct interpretation of the number when parsed back again.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | jn-0d-radix-prefix
Files: files | file ages | folders
SHA1: 20eeb7733d148c30bd5c14b6f237945f1b34222f
User & Date: jan.nijtmans 2017-06-14 10:04:05
Context
2017-06-26
10:20
Rebase branch "jn-0d-radix-prefix" back to trunk. No new changes check-in: e2b749751c user: jan.nijtmans tags: jn-0d-radix-prefix
2017-06-14
10:04
Little variation on Brian's proposal: Only prefix decimal number with '0d' when that's necessary for... check-in: 20eeb7733d user: jan.nijtmans tags: jn-0d-radix-prefix
07:54
Rebase to core-8-6-branch (who told that fossil doesn't know how to rebase ....) check-in: ae4471b37c user: jan.nijtmans tags: bsg-0d-radix-prefix
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to doc/format.n.

85
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
\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.
For \fBb\fR conversions, \fB0b\fR
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.
.SS "OPTIONAL FIELD WIDTH"
.PP






|
|
>







85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
\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.
For \fBb\fR conversions, \fB0b\fR
will be added to the beginning of the result unless it is zero.
For \fBd\fR conversions, \fB0d\fR there is no effect unless
the \fB0\fR specifier is used as well: In that case, \fB0d\fR or
\fB0D\fR (respectively) will be added to the beginning.
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.
.SS "OPTIONAL FIELD WIDTH"
.PP

Changes to generic/tclStringObj.c.

2033
2034
2035
2036
2037
2038
2039


2040
2041


2042
2043
2044
2045
2046
2047
2048
		    segmentLimit -= 2;
		    break;
		case 'b':
		    Tcl_AppendToObj(segment, "0b", 2);
		    segmentLimit -= 2;
		    break;
		case 'd':


		    Tcl_AppendToObj(segment, "0d", 2);
		    segmentLimit -= 2;


		    break;
		}
	    }

	    switch (ch) {
	    case 'd': {
		int length;






>
>
|
|
>
>







2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
		    segmentLimit -= 2;
		    break;
		case 'b':
		    Tcl_AppendToObj(segment, "0b", 2);
		    segmentLimit -= 2;
		    break;
		case 'd':
#if TCL_MAJOR_VERSION < 9
		    if (gotZero) {
			Tcl_AppendToObj(segment, "0d", 2);
			segmentLimit -= 2;
		    }
#endif
		    break;
		}
	    }

	    switch (ch) {
	    case 'd': {
		int length;

Changes to tests/format.test.

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92

93
94
95

96
97
98

99
100
101
102
103
104
105
} {0     06                   042                  041033               037777777764        }
test format-1.11.1 {integer formatting} longIs64bit {
    format "%-#5o %-#20o %#-20o %#-20o %#-20o" 0 6 34 16923 -12 -1
} {0     06                   042                  041033               01777777777777777777764}
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
} {abcd This is a very long test string. x x}
test format-2.2 {string formatting} {
    format "%20s %20s %20c %20s" abcd {This is a very long test string.} 120 x






|

<
<
|
<

|
<
>

|
<
>

|
<
>


<
>







74
75
76
77
78
79
80
81
82


83

84
85

86
87
88

89
90
91

92
93
94

95
96
97
98
99
100
101
102
} {0     06                   042                  041033               037777777764        }
test format-1.11.1 {integer formatting} longIs64bit {
    format "%-#5o %-#20o %#-20o %#-20o %#-20o" 0 6 34 16923 -12 -1
} {0     06                   042                  041033               01777777777777777777764}
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} {
    format "%#d %#d %#d %#d %#d" 0 6 34 16923 -12 -1


} {0 6 34 16923 -12}

test format-1.14 {integer formatting} longIs32bit {
    format "%#05d %#20d %#20d %#20d %#20d" 0 6 34 16923 -12 -1

} {0d000                    6                   34                16923                  -12}
test format-1.14.1 {integer formatting} longIs64bit {
    format "%#05d %#20d %#20d %#20d %#20d" 0 6 34 16923 -12 -1

} {0d000                    6                   34                16923             -12}
test format-1.15 {integer formatting} longIs32bit {
    format "%-#05d %-#20d %-#20d %-#20d %-#20d" 0 6 34 16923 -12 -1

} {0d000 6                    34                   16923                -12                 }
test format-1.15.1 {integer formatting} longIs64bit {
    format "%-#5d %-#20d %-#20d %-#20d %-#20d" 0 6 34 16923 -12 -1

} {0d000 6                    34                   16923                -12        }


test format-2.1 {string formatting} {
    format "%s %s %c %s" abcd {This is a very long test string.} 120 x
} {abcd This is a very long test string. x x}
test format-2.2 {string formatting} {
    format "%20s %20s %20c %20s" abcd {This is a very long test string.} 120 x