Skip to content

Commit

Permalink
Fix [c4f365470e]: Size modifiers j, q, z, t not implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Dec 13, 2024
2 parents 473c1fc + a11c69a commit c3d210e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
25 changes: 18 additions & 7 deletions generic/tclScan.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
/*
* Flag values used by Tcl_ScanObjCmd.
*/
enum ScanFlags {
SCAN_NOSKIP = 0x1, /* Don't skip blanks. */
SCAN_SUPPRESS = 0x2, /* Suppress assignment. */
SCAN_UNSIGNED = 0x4, /* Read an unsigned value. */
SCAN_WIDTH = 0x8, /* A width value was supplied. */

#define SCAN_NOSKIP 0x1 /* Don't skip blanks. */
#define SCAN_SUPPRESS 0x2 /* Suppress assignment. */
#define SCAN_UNSIGNED 0x4 /* Read an unsigned value. */
#define SCAN_WIDTH 0x8 /* A width value was supplied. */

#define SCAN_LONGER 0x400 /* Asked for a wide value. */
#define SCAN_BIG 0x800 /* Asked for a bignum value. */
SCAN_LONGER = 0x400, /* Asked for a wide value. */
SCAN_BIG = 0x800 /* Asked for a bignum value. */
};

/*
* The following structure contains the information associated with a
Expand Down Expand Up @@ -683,6 +684,7 @@ Tcl_ScanObjCmd(
format += TclUtfToUniChar(format, &ch);
} else if ((ch < 0x80) && isdigit(UCHAR(ch))) { /* INTL: "C" locale. */
char *formatEnd;
/* Note currently XPG3 range limited to INT_MAX to match type of objc */
value = strtoul(format-1, &formatEnd, 10);/* INTL: "C" locale. */
if (*formatEnd == '$') {
format = formatEnd+1;
Expand All @@ -707,6 +709,13 @@ Tcl_ScanObjCmd(
*/

switch (ch) {
case 'z':
case 't':
if (sizeof(void *) > sizeof(int)) {
flags |= SCAN_LONGER;
}
format += TclUtfToUniChar(format, &ch);
break;
case 'l':
if (*format == 'l') {
flags |= SCAN_BIG;
Expand All @@ -716,6 +725,8 @@ Tcl_ScanObjCmd(
}
/* FALLTHRU */
case 'L':
case 'j':
case 'q':
flags |= SCAN_LONGER;
/* FALLTHRU */
case 'h':
Expand Down
5 changes: 5 additions & 0 deletions tests/scan.test
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ test scan-5.20 {ignore digit separators} -setup {
} -body {
list [scan "10_23_45" %d_%d_%d a b c] $a $b $c
} -result {3 10 23 45}
test scan-5.21 {integer scanning, %j, %q, &z, %t} -setup {
set a {}; set b {}; set c {}; set d {}
} -body {
list [scan "42 43 44 45" "%jd %qd %zd %td" a b c d] $a $b $c $d
} -result {4 42 43 44 45}

test scan-6.1 {floating-point scanning} -setup {
set a {}; set b {}; set c {}; set d {}
Expand Down

0 comments on commit c3d210e

Please sign in to comment.