Tk Library Source Code

Artifact [b76b708a72]
Login

Artifact b76b708a72b9dd2d1c3e5b0888aa4e7ecd410921:

Attachment "476988.diff" to ticket [476988ffff] added by andreas_kupries 2001-12-12 04:48:53.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tcllib/tcllib/ChangeLog,v
retrieving revision 1.93
diff -u -r1.93 ChangeLog
--- ChangeLog	2001/12/11 17:58:20	1.93
+++ ChangeLog	2001/12/11 21:46:21
@@ -1,6 +1,8 @@
 2001-12-11  Andreas Kupries  <[email protected]>
 
-	* pop3: Bugfix for item #490151.
+	* pop3:     Bugfix for item #490151.
+
+	* textutil: Bugfix for item #476988.
 
 2001-12-10  Andreas Kupries  <[email protected]>
 
Index: modules/textutil/ChangeLog
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/textutil/ChangeLog,v
retrieving revision 1.15
diff -u -r1.15 ChangeLog
--- modules/textutil/ChangeLog	2001/12/11 05:54:21	1.15
+++ modules/textutil/ChangeLog	2001/12/11 21:46:21
@@ -1,3 +1,13 @@
+2001-12-11  Andreas Kupries  <[email protected]>
+
+	* textutil.n:
+	* split.test:
+	* split.tcl: Fixed item #476988, the handling of the empty input
+	  string, reported by Glenn Jackman
+	  <[email protected]>. Also added code to detect and
+	  handle an empty regular expression. In that case "splitx"
+	  degenerates to a simple "split".
+
 2001-12-10  Andreas Kupries  <[email protected]>
 
 	* expander.test:
Index: modules/textutil/split.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/textutil/split.tcl,v
retrieving revision 1.3
diff -u -r1.3 split.tcl
--- modules/textutil/split.tcl	2001/11/28 14:21:34	1.3
+++ modules/textutil/split.tcl	2001/12/11 21:46:21
@@ -47,6 +47,13 @@
 # }
 #
 proc ::textutil::split::splitx {str {regexp {[\t \r\n]+}}} {
+    # Bugfix 476988
+    if {[string length $str] == 0} {
+	return {}
+    }
+    if {[string length $regexp] == 0} {
+	return [::split $str ""]
+    }
     set list  {}
     set start 0
     while {[regexp -start $start -indices -- $regexp $str match submatch]} {
Index: modules/textutil/split.test
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/textutil/split.test,v
retrieving revision 1.1
diff -u -r1.1 split.test
--- modules/textutil/split.test	2000/11/02 19:38:13	1.1
+++ modules/textutil/split.test	2001/12/11 21:46:21
@@ -1,4 +1,5 @@
 # split.test:  tests for the split sub-package of the textutil package.
+# -*- tcl -*-
 #
 # This file contains a collection of tests for one or more of the Tcl
 # built-in commands.  Sourcing this file into Tcl runs the tests and
@@ -76,9 +77,9 @@
 " "\[ ,()\.\t\r\n\]+"
 } [ list {} Determines whether the regular expression exp matches part or all of string and returns 1 if it does 0 if it doesn't unless -inline is specified see below Regular expression matching is described in the re_syntax reference page If additional arguments are specified after string then they are treated as the names of variables in which to return information about which part s of string matched exp MatchVar will be set to the range of string that matched all of exp The first subMatchVar will contain the characters in string that matched the leftmost parenthesized subexpression within exp the next subMatchVar will contain the characters that matched the next parenthesized subexpression to the right in exp and so on {} ]
 
-# these tests show the effect inducted by the usage of parenthesed in the regexp
-# Basically, the parenthesed operator is returned with the splitted list
-# The 3.5 and 3.6 show complexe cases. Try to understand.
+# these tests show the effect inducted by the usage of parenthesed in
+# the regexp Basically, the parenthesed operator is returned with the
+# splitted list The 3.5 and 3.6 show complex cases. Try to understand.
 
 test splitx-3.1 {split string with simple regexp} {
     ::textutil::splitx "Nobody is perfect" "\[oe\]+"
@@ -104,3 +105,19 @@
     ::textutil::splitx "Nobody is perfect" "(\[oe\]+|rf)"
 } [ list N o b o [ list dy is p ] e {} rf {} e ct ]
 
+
+test splitx-4.0 {splitting of empty strings} {
+    ::textutil::splitx "" "f"
+} {}
+
+test splitx-4.1 {splitting of empty strings} {
+    ::textutil::splitx ""
+} {}
+
+test splitx-4.2 {splitting of empty strings} {
+    ::textutil::splitx "" ""
+} {}
+
+test splitx-5.0 {splitting using an empty regexp} {
+    ::textutil::splitx "fooo bar bas" ""
+} {f o o o { } b a r { } b a s}
Index: modules/textutil/textutil.n
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/textutil/textutil.n,v
retrieving revision 1.8
diff -u -r1.8 textutil.n
--- modules/textutil/textutil.n	2001/11/12 18:33:10	1.8
+++ modules/textutil/textutil.n	2001/12/11 21:46:21
@@ -115,15 +115,15 @@
 single word is longer than '-length'. If set to \fItrue\fR, words that
 are longer than '-length' are split so that no line exceeds the
 specified '-length'. Default to \fIfalse\fR.
-
 .TP
 \fBtextutil::splitx\fR \fIstring {regexp [\t \r\n\]+}\fR
 Split the \fIstring\fP and return a list. The string is split
 according to the regular expression \fIregexp\fR instead of a simple
 list of chars. Note that if you add parenthesis into the \fIregexp\fR,
-the parentheses part of separator would be added into list as additional
-element.
-
+the parentheses part of separator would be added into list as
+additional element. If the \fIstring\fR is empty the result is the
+empty list, like for \fBsplit\fR. If \fIregexp\fR is empty the
+\fIstring\fR is split at every character, like \fBsplit\fR does.
 .TP
 \fBtextutil::tabify\fR \fIstring {num 8}\fR
 Tabify the \fIstring\fP by replacing any substring of \fInum\fP space