summaryrefslogtreecommitdiffstats
path: root/generic/tclStrToD.c
diff options
context:
space:
mode:
authorgriffin <briang42@easystreet.net>2020-05-23 03:32:30 (GMT)
committergriffin <briang42@easystreet.net>2020-05-23 03:32:30 (GMT)
commit6d2fb7b84d5d50f685186f9866337e167a249118 (patch)
tree4bd41ec584be2147b21626aa9001dc52dac3f6cb /generic/tclStrToD.c
parente38608eeb31429e3684101d8bcf151ea5fe29ed4 (diff)
downloadtcl-6d2fb7b84d5d50f685186f9866337e167a249118.zip
tcl-6d2fb7b84d5d50f685186f9866337e167a249118.tar.gz
tcl-6d2fb7b84d5d50f685186f9866337e167a249118.tar.bz2
Update for TIP-551:
Add documentation for this feature to the expr man page. The keyword "integer value" has been added to the string and expr man page. Added TCL_PARSE_NO_UNDERSCORE flag so that the digit separator can be disabled when need when calling TclParseNumber. Disabled digit separator in the "scan" command when scanning integers and floating-point numbers. This is the one place where existing code may rely on number parsing to stop at an underscore. Disallow underscore between the leading 0 and the radix specifiers 'x', 'o', 'b', and 'd'. Added tests for disallowed underscore use and scan with underscores between digits in the source string.
Diffstat (limited to 'generic/tclStrToD.c')
-rw-r--r--generic/tclStrToD.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c
index f1bf0c6..41dbd0d 100644
--- a/generic/tclStrToD.c
+++ b/generic/tclStrToD.c
@@ -639,8 +639,7 @@ TclParseNumber(
acceptPoint = p;
acceptLen = len;
if (c == 'x' || c == 'X') {
- under = 0;
- if (flags & (TCL_PARSE_OCTAL_ONLY|TCL_PARSE_BINARY_ONLY)) {
+ if (flags & (TCL_PARSE_OCTAL_ONLY|TCL_PARSE_BINARY_ONLY) || under) {
goto endgame;
}
state = ZERO_X;
@@ -653,8 +652,7 @@ TclParseNumber(
goto zeroo;
}
if (c == 'b' || c == 'B') {
- under = 0;
- if (flags & TCL_PARSE_OCTAL_ONLY) {
+ if ((flags & TCL_PARSE_OCTAL_ONLY) || under) {
goto endgame;
}
state = ZERO_B;
@@ -664,13 +662,17 @@ TclParseNumber(
goto zerob;
}
if (c == 'o' || c == 'O') {
+ if (under) {
+ goto endgame;
+ }
explicitOctal = 1;
- under = 0;
state = ZERO_O;
break;
}
if (c == 'd' || c == 'D') {
- under = 0;
+ if (under) {
+ goto endgame;
+ }
state = ZERO_D;
break;
}
@@ -741,7 +743,7 @@ TclParseNumber(
numTrailZeros = 0;
state = OCTAL;
break;
- } else if (c == '_') {
+ } else if (c == '_' && !(flags & TCL_PARSE_NO_UNDERSCORE)) {
/* Ignore numeric "white space" */
under = 1;
break;
@@ -832,7 +834,7 @@ TclParseNumber(
} else if (c >= 'a' && c <= 'f') {
under = 0;
d = (c-'a'+10);
- } else if (c == '_') {
+ } else if (c == '_' && !(flags & TCL_PARSE_NO_UNDERSCORE)) {
/* Ignore numeric "white space" */
under = 1;
break;
@@ -878,7 +880,7 @@ TclParseNumber(
under = 0;
state = BINARY;
break;
- } else if (c == '_') {
+ } else if (c == '_' && !(flags & TCL_PARSE_NO_UNDERSCORE)) {
/* Ignore numeric "white space" */
under = 1;
break;
@@ -918,7 +920,7 @@ TclParseNumber(
under = 0;
numTrailZeros++;
} else if ( ! isdigit(UCHAR(c))) {
- if (c == '_') {
+ if (c == '_' && !(flags & TCL_PARSE_NO_UNDERSCORE)) {
/* Ignore numeric "white space" */
under = 1;
break;
@@ -959,7 +961,7 @@ TclParseNumber(
under = 0;
state = DECIMAL;
break;
- } else if (c == '_') {
+ } else if (c == '_' && !(flags & TCL_PARSE_NO_UNDERSCORE)) {
/* Ignore numeric "white space" */
under = 1;
break;
@@ -1016,7 +1018,7 @@ TclParseNumber(
under = 0;
state = FRACTION;
break;
- } else if (c == '_') {
+ } else if (c == '_' && !(flags & TCL_PARSE_NO_UNDERSCORE)) {
/* Ignore numeric "white space" */
under = 1;
break;
@@ -1053,7 +1055,7 @@ TclParseNumber(
under = 0;
state = EXPONENT;
break;
- } else if (c == '_') {
+ } else if (c == '_' && !(flags & TCL_PARSE_NO_UNDERSCORE)) {
/* Ignore numeric "white space" */
under = 1;
break;
@@ -1078,7 +1080,7 @@ TclParseNumber(
under = 0;
state = EXPONENT;
break;
- } else if (c == '_') {
+ } else if (c == '_' && !(flags & TCL_PARSE_NO_UNDERSCORE)) {
/* Ignore numeric "white space" */
under = 1;
break;