Index: split.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/textutil/split.tcl,v
retrieving revision 1.5
diff -r1.5 split.tcl
5a6
> 	namespace export splitn
10a12
> 	proc splitn [list str [list len 1]] {}
14a17,18
>     namespace import -force split::splitn
>     namespace export splitn
102a107,155
> 
> #
> # splitn --
> #
> # splitn splits the string $str into chunks of length $len.  These
> # chunks are returned as a list.
> #
> # If $str really contains a ByteArray object (as retrieved from binary
> # encoded channels) splitn must honor this by splitting the string
> # into chunks of $len bytes.
> #
> # It is an error to call splitn with a nonpositive $len.
> #
> # If splitn is called with an empty string, it returns the empty list.
> #
> # If the length of $str is not an entire multiple of the chunk length,
> # the last chunk in the generated list will be shorter than $len.
> #
> # The implementation presented here was given by Bryan Oakley, as
> # part of a ``contest'' I staged on c.l.t in July 2004.  I selected
> # this version, as it does not rely on runtime generated code, is
> # very fast for chunk size one, not too bad in all the other cases,
> # and uses [split] or [string range] which have been around for quite
> # some time.
> #
> # -- Robert Suetterlin (robert@mpe.mpg.de)
> #
> proc ::textutil::split::splitn [list str [list len 1]] {
> 
>     if {$len <= 0} {
>         error "len must be > 0"
>     }
> 
>     if {$len == 1} {
>         return [split $str {}]
>     }
> 
>     set result [list]
>     set max [string length $str]
>     set i 0
>     set j [expr {$len -1}]
>     while {$i < $max} {
>         lappend result [string range $str $i $j]
>         incr i $len
>         incr j $len
>     }
> 
>     return $result
> }
Index: split.test
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/textutil/split.test,v
retrieving revision 1.2
diff -r1.2 split.test
19a20,49
> test splitn-0.1 {split empty string} {
>     ::textutil::splitn ""
> } [list]
> 
> test splitn-0.2 {split empty string with explicit lenght 1} {
>     ::textutil::splitn "" 1
> } [list]
> 
> test splitn-0.3 {split empty string with explicit lenght 2} {
>     ::textutil::splitn "" 2
> } [list]
> 
> test splitn-1.1 {split simple string} {
>     splitn "abc"
> } [list a b c]
> 
> test splitn-1.2 {split simple string with explicit length 1} {
>     splitn "abc" 1
> } [list a b c]
> 
> test splitn-1.3 {split simple string with explicit length 2} {
>     splitn "abc" 2
> } [list ab c]
> 
> test splitn-2.1 {split with nonpositive lenght ->error!} -body {
>     splitn "abc" 0
> } -returnCodes [list error] -result "len must be > 0"
> 
> ###################################################
> 
