From 9ce6a4582944552a01b327cb06eb7b420e914f08 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 30 May 2024 21:26:39 +0000 Subject: Let's [9c258a841a|fix] the j%j/%q type specifiers, so they behave like C in scripts, and document them --- doc/format.n | 12 +++++------- generic/tclStringObj.c | 8 +++++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/doc/format.n b/doc/format.n index b647349..b0a0107 100644 --- a/doc/format.n +++ b/doc/format.n @@ -138,19 +138,17 @@ If it is \fBll\fR it specifies that an integer value is taken without truncation for conversion to a formatted substring. If it is \fBh\fR it specifies that an integer value is truncated to a 16-bit range before converting. This option is rarely useful. -If it is \fBl\fR it specifies that the integer value is -truncated to the same range as that produced by the \fBwide()\fR +If it is \fBl\fR (or \fBj\fR or \fBq\fR) it specifies that the integer value +is truncated to the same range as that produced by the \fBwide()\fR function of the \fBexpr\fR command (at least a 64-bit range). If it is \fBz\fR or \fBt\fR it specifies that the integer value is truncated to the range determined by the value of the \fBpointerSize\fR element of the \fBtcl_platform\fR array. If it is \fBL\fR it specifies that an integer or double value is taken without truncation for conversion to a formatted substring. -If neither \fBh\fR nor \fBl\fR nor \fBL\fR are present, the integer value is -truncated to the same range as that produced by the \fBint()\fR -function of the \fBexpr\fR command (at least a 32-bit range, but -determined by the value of the \fBwordSize\fR element of the -\fBtcl_platform\fR array). +If neither of those are present, the integer value is +truncated to the range determined by the value of the +\fBwordSize\fR element of the \fBtcl_platform\fR array). .SS "MANDATORY CONVERSION TYPE" .PP The last thing in a conversion specifier is an alphabetic character diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 494451d..b4da1a9 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2457,6 +2457,12 @@ Tcl_AppendFormatToObj( format += step; step = TclUtfToUniChar(format, &ch); } + } else if ((ch == 'q') || (ch == 'j')) { + format += step; + step = TclUtfToUniChar(format, &ch); +#ifndef TCL_WIDE_INT_IS_LONG + useWide = 1; +#endif } else if ((ch == 't') || (ch == 'z')) { format += step; step = TclUtfToUniChar(format, &ch); @@ -2465,7 +2471,7 @@ Tcl_AppendFormatToObj( useWide = 1; } #endif - } else if ((ch == 'q') || (ch == 'j') || (ch == 'L')) { + } else if (ch == 'L') { format += step; step = TclUtfToUniChar(format, &ch); useBig = 1; -- cgit v0.12