Tk Library Source Code

View Ticket
Login
Ticket UUID: 1063774
Title: [splitn string ?len=1?] split string in chunks of length len
Type: Patch Version: None
Submitter: suetterlin Created on: 2004-11-10 12:37:27
Subsystem: textutil Assigned To: andreas_kupries
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2005-02-19 13:00:27
Resolution: Accepted Closed By: andreas_kupries
    Closed on: 2005-02-19 06:00:27
Description:
Dear tcllib maintainers, 
 
This is a patch against tcllib, adding a new procedure splitn to 
split.tcl and in addition having relevant tests in split.test. 
 
[splitn string ?len=1?] will split string into chunks of length $len.  
These are returned in a list.  If the string length is not an entire 
multiple of $len, the last chunk will be short.  With an empty 
string the empty list is returned.  And a nonpositive len will result 
in an error. 
 
The implementation used for splitn is almost identical to code 
submitted by Bryan Oakley in a ``contest'' I did on c.l.t ... as this 
was the first submitted code that used more than one algorithm 
depending on the string length, I asked B.O. if I could use it.  
Unfortunately I got no reply sofar.  But my spare time is running 
short, so I will submit this patch now.  Once I get B.O.'s reply I 
will forward it to the tcllib project. 
 
Except as stated above the code is in the public domain. 
 
Best regards, Robert S.
User Comments: andreas_kupries added on 2005-02-19 13:00:27:
Logged In: YES 
user_id=75003

Committed to head.

andreas_kupries added on 2005-02-19 07:13:59:

File Added - 121843: tcllib.udiff

andreas_kupries added on 2005-02-19 07:13:56:
Logged In: YES 
user_id=75003

Reassigned to myself for work. Got mail that Bryan had
already given permission.

I am attaching a new patch which corrects a number of small
problems I had with the original submission:

* Using unified-diff format (option -u for diff).
  Much more readable regarding the changes
  which were made.

* Fixed problems in the testsuite:
   - splitn => textutil::splitn
   - test 2.1 used tcltest 2 feature.
     Nothing else does in the textutil testsuite.
     Rewritten to regular v1 format.

* proc splitn [list str [list len 1]] {...} rewritten to
   proc split {str {len 1}}

   The list construction was used by splitx only to
   get better quotation for the default regex, and
   only for older versions of Tcl.

andreas_kupries added on 2005-02-15 07:12:59:
Logged In: YES 
user_id=75003

Bryan, what is your response regarding our ability to use
this code ?

suetterlin added on 2004-11-10 19:37:28:

File Added - 108272: tcllib.diff

Attachments: