Tcl Source Code

Artifact [b631ccd453]
Login

Artifact b631ccd45347b0132e5d301fa7f864ca2120ed85:

Attachment "string_is_bignum.txt" to ticket [2581150fff] added by decosterjos 2009-02-09 17:57:01.
Index: doc/string.n
===================================================================
RCS file: /cvsroot/tcl/tcl/doc/string.n,v
retrieving revision 1.45
diff -w -u -r1.45 string.n
--- doc/string.n	17 Oct 2008 10:22:25 -0000	1.45
+++ doc/string.n	9 Feb 2009 10:25:07 -0000
@@ -147,6 +147,9 @@
 .IP \fBascii\fR 12
 Any character with a value less than \eu0080 (those that are in the
 7\-bit ascii range).
+.IP \fBbignum\fR 12
+Any of the valid string formats for an integer value in Tcl, with optional
+surrounding whitespace.
 .IP \fBboolean\fR 12
 Any of the forms allowed to \fBTcl_GetBoolean\fR.
 .IP \fBcontrol\fR 12
Index: generic/tclCmdMZ.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclCmdMZ.c,v
retrieving revision 1.179
diff -w -u -r1.179 tclCmdMZ.c
--- generic/tclCmdMZ.c	5 Feb 2009 22:12:44 -0000	1.179
+++ generic/tclCmdMZ.c	9 Feb 2009 10:25:10 -0000
@@ -1413,14 +1413,15 @@
 	"graph",	"integer",	"list",		"lower",
 	"print",	"punct",	"space",	"true",
 	"upper",	"wideinteger",	"wordchar",	"xdigit",
-	NULL
+	"bignum",       NULL
     };
     enum isOptions {
 	STR_IS_ALNUM, STR_IS_ALPHA,	STR_IS_ASCII,  STR_IS_CONTROL,
 	STR_IS_BOOL,  STR_IS_DIGIT,	STR_IS_DOUBLE, STR_IS_FALSE,
 	STR_IS_GRAPH, STR_IS_INT,	STR_IS_LIST,   STR_IS_LOWER,
 	STR_IS_PRINT, STR_IS_PUNCT, STR_IS_SPACE,  STR_IS_TRUE,
-	STR_IS_UPPER, STR_IS_WIDE,	STR_IS_WORD,   STR_IS_XDIGIT
+	STR_IS_UPPER, STR_IS_WIDE,	STR_IS_WORD,   STR_IS_XDIGIT,
+	STR_IS_BIGNUM
     };
 
     if (objc < 3 || objc > 6) {
@@ -1531,6 +1532,11 @@
     case STR_IS_GRAPH:
 	chcomp = Tcl_UniCharIsGraph;
 	break;
+    case STR_IS_BIGNUM:
+	if (TCL_OK == Tcl_GetBignumFromObj(NULL, objPtr, &i)) {
+	    break;
+	}
+	goto failedIntParse;
     case STR_IS_INT:
 	if (TCL_OK == TclGetIntFromObj(NULL, objPtr, &i)) {
 	    break;
Index: tests/string.test
===================================================================
RCS file: /cvsroot/tcl/tcl/tests/string.test,v
retrieving revision 1.76
diff -w -u -r1.76 string.test
--- tests/string.test	14 Oct 2008 18:49:47 -0000	1.76
+++ tests/string.test	9 Feb 2009 10:25:11 -0000
@@ -314,10 +314,10 @@
 } {1 {wrong # args: should be "string is class ?-strict? ?-failindex var? str"}}
 test string-6.5 {string is, class check} {
     list [catch {string is bogus str} msg] $msg
-} {1 {bad class "bogus": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, list, lower, print, punct, space, true, upper, wideinteger, wordchar, or xdigit}}
+} {1 {bad class "bogus": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, list, lower, print, punct, space, true, upper, wideinteger, wordchar, xdigit, or bignum}}
 test string-6.6 {string is, ambiguous class} {
     list [catch {string is al str} msg] $msg
-} {1 {ambiguous class "al": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, list, lower, print, punct, space, true, upper, wideinteger, wordchar, or xdigit}}
+} {1 {ambiguous class "al": must be alnum, alpha, ascii, control, boolean, digit, double, false, graph, integer, list, lower, print, punct, space, true, upper, wideinteger, wordchar, xdigit, or bignum}}
 test string-6.7 {string is alpha, all ok} {
     string is alpha -strict -failindex var abc
 } 1
@@ -676,6 +676,78 @@
 test string-6.109 {string is double, Bug 1360532} {
     string is double 1\u00a0
 } 0
+test string-6.110 {string is bignum, true} {
+    string is bignum +1234567890
+} 1
+test string-6.111 {string is bignum, true on type} {
+    string is bignum [expr wide(50.0)]
+} 1
+test string-6.112 {string is bignum, true} {
+    string is bignum [list -10]
+} 1
+test string-6.113 {string is bignum, true as hex} {
+    string is bignum 0xabcdef
+} 1
+test string-6.114 {string is bignum, true as octal} {
+    string is bignum 0123456
+} 1
+test string-6.115 {string is bignum, true with whitespace} {
+    string is bignum "  \n1234\v"
+} 1
+test string-6.116 {string is bignum, false} {
+    list [string is bignum -fail var 123abc] $var
+} {0 3}
+test string-6.117 {string is bignum, false} {
+    list [string is bignum -fail var 123123123123123123123123123123123123123123123123123123123123123123123123123123123123abc] $var
+} {0 84}
+test string-6.118 {string is bignum, false} {
+    list [string is bignum -fail var [expr double(1)]] $var
+} {0 1}
+test string-6.119 {string is bignum, false} {
+    list [string is bignum -fail var "    "] $var
+} {0 0}
+test string-6.120 {string is bignum, false on bad octal} {
+    list [string is bignum -fail var 0o36963] $var
+} {0 4}
+test string-6.121.1 {string is bignum, false on bad octal} {
+    list [string is bignum -fail var 0o36963] $var
+} {0 4}
+test string-6.122 {string is bignum, false on bad hex} {
+    list [string is bignum -fail var 0X345XYZ] $var
+} {0 5}
+test string-6.123 {string is bignum, bad integers} {
+    # SF bug #634856
+    set result ""
+    set numbers [list 1 +1 ++1 +-1 -+1 -1 --1 "- +1"]
+    foreach num $numbers {
+	lappend result [string is bignum -strict $num]
+    }
+    set result
+} {1 1 0 0 0 1 0 0}
+test string-6.124 {string is bignum, true} {
+    string is bignum +1234567890123456789012345678901234567890
+} 1
+test string-6.125 {string is bignum, true} {
+    string is bignum [list -10000000000000000000000000000000000000000000000000000000000000000000000000000000000000]
+} 1
+test string-6.126 {string is bignum, true as hex} {
+    string is bignum 0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef
+} 1
+test string-6.127 {string is bignum, true as octal} {
+    string is bignum 0123456112341234561234565623456123456123456123456123456123456123456123456123456123456
+} 1
+test string-6.128 {string is bignum, true with whitespace} {
+    string is bignum "  \n12340000000000000000000000000000000000000000000000000000000000000000000000000000000000000\v"
+} 1
+test string-6.129 {string is bignum, false on bad octal} {
+    list [string is bignum -fail var 0o1234561123412345612345656234561234561234561234561234561234561234561234561234561234536963] $var
+} {0 87}
+test string-6.130.1 {string is bignum, false on bad octal} {
+    list [string is bignum -fail var 0o1234561123412345612345656234561234561234561234561234561234561234561234561234561234536963] $var
+} {0 87}
+test string-6.131 {string is bignum, false on bad hex} {
+    list [string is bignum -fail var 0X12345611234123456123456562345612345612345612345612345612345612345612345612345612345345XYZ] $var
+} {0 88}
 
 catch {rename largest_int {}}