Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-04-17
06:00 • Closed ticket [218721ffff]: Updated string command plus 3 other changes artifact: 6f6c9e2036 user: dgp
06:00 • Ticket [218721ffff]: 2 changes artifact: e2159dc7d4 user: dgp
06:00 • Open ticket [218721ffff]. artifact: 9aed867356 user: dgp
2000-10-26
08:27 • Closed ticket [218721ffff]. artifact: b192f49a81 user: welch
01:04 • New ticket [218721ffff]. artifact: 0e584d19ea user: nobody

Updated string command

Closed / Fixed218721ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:04:33
OriginalBugID: 1845 RFE
Version: 8.1b3
SubmitDate: '1999-04-16'
LastModified: '1999-08-06'
Severity: LOW
Status: Released
Submitter: pat
ChangedBy: hobbs
OS: Other
Machine: NA
FixedDate: '1999-08-06'
FixedInVersion: 8.1.1
ClosedDate: '2000-10-25'


Name:
Jeffrey Hobbs

CustomShell:
This is the core mod, baby!

Comments:
I think this fully tested patch would make a great addition to 8.1,
    but realizing that that is close to final, they should definitely be
    folded into 8.2.  If you need good examples of where this saves times
    or improves logic for common tasks. you're not coding enough Tcl :^).
    
    The implementations were done to maintain 100% backwards compatibility
    with working code (changing the options to an arg can obviously change
    what error strings arise), and reduce any loss of speed (the only method
    that actually attained a speed loss was string index, as I throw a
    Tcl_NumUtfChars call in to support end-1 like indices, and that is not
    major).

DesiredBehavior:
There is some basic functionality missing in Tcl that causes commonly
    required functions to need multiple Tcl calls.  I have upgraded the
    core string command (with some minor list indexing benefits) to give
    better core functionality for string manipulation in Tcl.  These
    functions are fully tested (test suite included in patch, with all
    mods necessary to other tests) and documented.
    
    I made the following modifications:
    
    * string compare now takes optional length arg
    (for strncmp behavior)
    
    * added string equal (just a few lines of code blended
    in with string compare)
    
    * added string icompare/iequal for case-insensitive comparisons
    
    * string index's index can now be ?end[+-]?expression
    I made this change in the private TclGetIntForIndex,
    which means that the list commands also benefit, as
    well as string range, et al.
    
    * added [string repeat string count]
    Repeats given string <count> number of times
    
    * added string replace, string equiv to lreplace
      (quasi opposite of string range):
    string replace first last ?string?
    Example of use, replacing end of string with ...
    should the string be more than 16 chars long:
    string replace $string 16 end "..."
    This just returns the string len < 16, so it
    will only affect the long strings.
    
    * added optional first and last args to string to*
    This allows you to just affect certain regions of
    a string with the command (like just capping the
    first letter).  I found the original totitle to
    be too draconian to be useful.
    
    * added [string map charMap string]
    where charMap is a {from to from to} list that equates to
    what one might get from [array get].  Each <from> and <to>
    can be multiple chars (or none at all).  For Tcl/CGI users,
    this is a MAJOR speed booster.

Patch:
The patch comes to 64KB with full doc and test suite changes
against the tcl8.1b3 sources.
http://www.hobbs.wservice.com/tcl/capp/newstring.txt

PatchFiles:
C: tclUtil.c && tclCmdMZ.c
    doc: string.n
    tests: string.test cmd*.test l*.test error.test



Added to 8.1.1. 
-- 08/06/1999 hobbs
welch Closed ticket [218721ffff]. [History diff]2000-10-26 08:27:13
dgp Open ticket [218721ffff]. [History diff]2001-04-17 06:00:16
dgp Ticket [218721ffff]: 2 changes [History diff]2001-04-17 06:00:17
dgp Closed ticket [218721ffff]. [History diff]2001-04-17 06:00:51
Log in (anonymous is fine) to add a comment.