Tcl Library Source Code

Changes On Branch tkt-85a0ec8f50-ak
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch tkt-85a0ec8f50-ak Excluding Merge-Ins

This is equivalent to a diff from c76dc6a3fc to 31bfe3ad8e

2017-08-07
23:54
Merged fix for ticket [85a0ec8f50]. check-in: 98a32c3965 user: aku tags: trunk
23:53
Fix infinite loop when splitx is invoked with a regexp matching the empty string. Bumped version. Extended testsuite. Closed-Leaf check-in: 31bfe3ad8e user: aku tags: tkt-85a0ec8f50-ak
23:41
Merged fix for ticket [cb043ecc70e0e90bf]. check-in: c76dc6a3fc user: aku tags: trunk
23:40
Fixed missing version bump for bugfix. Fixed warning in statistics documentation. Closed-Leaf check-in: bf6666afc5 user: aku tags: avl-fix-areaPolygon-and-more
2017-06-05
21:00
Merged fixes for tkt [71deadcf96]. check-in: 78d7722e1e user: aku tags: trunk

Changes to modules/textutil/pkgIndex.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
if {![package vsatisfies [package provide Tcl] 8.2]} {
    # FRINK: nocheck
    return
}
package ifneeded textutil           0.8   [list source [file join $dir textutil.tcl]]
package ifneeded textutil::adjust   0.7.3 [list source [file join $dir adjust.tcl]]
package ifneeded textutil::split    0.7   [list source [file join $dir split.tcl]]
package ifneeded textutil::trim     0.7   [list source [file join $dir trim.tcl]]
package ifneeded textutil::tabify   0.7   [list source [file join $dir tabify.tcl]]
package ifneeded textutil::repeat   0.7   [list source [file join $dir repeat.tcl]]
package ifneeded textutil::string   0.8   [list source [file join $dir string.tcl]]
package ifneeded textutil::expander 1.3.1 [list source [file join $dir expander.tcl]]






|





1
2
3
4
5
6
7
8
9
10
11
12
if {![package vsatisfies [package provide Tcl] 8.2]} {
    # FRINK: nocheck
    return
}
package ifneeded textutil           0.8   [list source [file join $dir textutil.tcl]]
package ifneeded textutil::adjust   0.7.3 [list source [file join $dir adjust.tcl]]
package ifneeded textutil::split    0.8   [list source [file join $dir split.tcl]]
package ifneeded textutil::trim     0.7   [list source [file join $dir trim.tcl]]
package ifneeded textutil::tabify   0.7   [list source [file join $dir tabify.tcl]]
package ifneeded textutil::repeat   0.7   [list source [file join $dir repeat.tcl]]
package ifneeded textutil::string   0.8   [list source [file join $dir string.tcl]]
package ifneeded textutil::expander 1.3.1 [list source [file join $dir expander.tcl]]

Changes to modules/textutil/split.tcl.

58
59
60
61
62
63
64





65
66
67
68
69
70
71
        # 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]} {
            foreach {subStart subEnd} $submatch break
            foreach {matchStart matchEnd} $match break
            incr matchStart -1
            incr matchEnd







>
>
>
>
>







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
        # Bugfix 476988
        if {[string length $str] == 0} {
            return {}
        }
        if {[string length $regexp] == 0} {
            return [::split $str ""]
        }
	if {[regexp $regexp {}]} {
	    return -code error \
		"splitting on regexp \"$regexp\" would cause infinite loop"
	}

        set list  {}
        set start 0
        while {[regexp -start $start -indices -- $regexp $str match submatch]} {
            foreach {subStart subEnd} $submatch break
            foreach {matchStart matchEnd} $match break
            incr matchStart -1
            incr matchEnd
85
86
87
88
89
90
91




92
93
94
95
96
97
98

        if {[string length $str] == 0} {
            return {}
        }
        if {[string length $regexp] == 0} {
            return [::split $str {}]
        }





        set list  {}
        while {[regexp -indices -- $regexp $str match submatch]} {
            lappend list [string range $str 0 [expr {[lindex $match 0] -1}]]
            if {[lindex $submatch 0] >= 0} {
                lappend list [string range $str [lindex $submatch 0] \
                                  [lindex $submatch 1]]







>
>
>
>







90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

        if {[string length $str] == 0} {
            return {}
        }
        if {[string length $regexp] == 0} {
            return [::split $str {}]
        }
	if {[regexp $regexp {}]} {
	    return -code error \
		"splitting on regexp \"$regexp\" would cause infinite loop"
	}

        set list  {}
        while {[regexp -indices -- $regexp $str match submatch]} {
            lappend list [string range $str 0 [expr {[lindex $match 0] -1}]]
            if {[lindex $submatch 0] >= 0} {
                lappend list [string range $str [lindex $submatch 0] \
                                  [lindex $submatch 1]]
160
161
162
163
164
165
166
167
namespace eval ::textutil::split {
    namespace export splitx splitn
}

# ### ### ### ######### ######### #########
## Ready

package provide textutil::split 0.7







|
169
170
171
172
173
174
175
176
namespace eval ::textutil::split {
    namespace export splitx splitn
}

# ### ### ### ######### ######### #########
## Ready

package provide textutil::split 0.8

Changes to modules/textutil/split.test.

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

# -------------------------------------------------------------------------

test splitn-0.1 {split empty string} {
    ::textutil::split::splitn ""
} [list]

test splitn-0.2 {split empty string with explicit lenght 1} {
    ::textutil::split::splitn "" 1
} [list]

test splitn-0.3 {split empty string with explicit lenght 2} {
    ::textutil::split::splitn "" 2
} [list]

test splitn-1.1 {split simple string} {
    ::textutil::split::splitn "abc"
} [list a b c]

test splitn-1.2 {split simple string with explicit length 1} {
    ::textutil::split::splitn "abc" 1
} [list a b c]

test splitn-1.3 {split simple string with explicit length 2} {
    ::textutil::split::splitn "abc" 2
} [list ab c]

test splitn-2.1 {split with nonpositive lenght ->error!} {
    catch {::textutil::split::splitn "abc" 0} msg
    set msg
} {len must be > 0}

###################################################

test splitx-0.1 {split simple string} {







|



|















|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

# -------------------------------------------------------------------------

test splitn-0.1 {split empty string} {
    ::textutil::split::splitn ""
} [list]

test splitn-0.2 {split empty string with explicit length 1} {
    ::textutil::split::splitn "" 1
} [list]

test splitn-0.3 {split empty string with explicit length 2} {
    ::textutil::split::splitn "" 2
} [list]

test splitn-1.1 {split simple string} {
    ::textutil::split::splitn "abc"
} [list a b c]

test splitn-1.2 {split simple string with explicit length 1} {
    ::textutil::split::splitn "abc" 1
} [list a b c]

test splitn-1.3 {split simple string with explicit length 2} {
    ::textutil::split::splitn "abc" 2
} [list ab c]

test splitn-2.1 {split with nonpositive length ->error!} {
    catch {::textutil::split::splitn "abc" 0} msg
    set msg
} {len must be > 0}

###################################################

test splitx-0.1 {split simple string} {
152
153
154
155
156
157
158







test splitx-4.2 {splitting of empty strings} {
    ::textutil::split::splitx "" ""
} {}

test splitx-5.0 {splitting using an empty regexp} {
    ::textutil::split::splitx "fooo bar bas" ""
} {f o o o { } b a r { } b a s}














>
>
>
>
>
>
>
152
153
154
155
156
157
158
159
160
161
162
163
164
165
test splitx-4.2 {splitting of empty strings} {
    ::textutil::split::splitx "" ""
} {}

test splitx-5.0 {splitting using an empty regexp} {
    ::textutil::split::splitx "fooo bar bas" ""
} {f o o o { } b a r { } b a s}


test splitx-6.0 {split with regexp matching "" causes infinite loop eating RAM} {
    list [catch {
	::textutil::split::splitx "Hello, Word" "|"
    } msg] $msg
} {1 {splitting on regexp "|" would cause infinite loop}}

Changes to modules/textutil/textutil_split.man.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

[manpage_begin textutil::split n 0.7]
[see_also regexp(n)]
[see_also split(n)]
[see_also string(n)]
[keywords {regular expression}]
[keywords split]
[keywords string]
[moddesc   {Text and string utilities, macro processing}]
[titledesc {Procedures to split texts}]
[category  {Text processing}]
[require Tcl 8.2]
[require textutil::split [opt 0.7]]
[description]

The package [package textutil::split] provides commands that split
strings by size and arbitrary regular expressions.

[para]

>
|










|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[vset VERSION 0.8]
[manpage_begin textutil::split n [vset VERSION]]
[see_also regexp(n)]
[see_also split(n)]
[see_also string(n)]
[keywords {regular expression}]
[keywords split]
[keywords string]
[moddesc   {Text and string utilities, macro processing}]
[titledesc {Procedures to split texts}]
[category  {Text processing}]
[require Tcl 8.2]
[require textutil::split [opt [vset VERSION]]]
[description]

The package [package textutil::split] provides commands that split
strings by size and arbitrary regular expressions.

[para]