|
2009-07-14
| ||
| 19:54 | • Closed ticket [219378ffff]: string range to take index list plus 7 other c... artifact: 5d1e63762f user: dkf | |
| 19:54 | • Ticket [219378ffff]: 4 changes artifact: d66330a3ae user: dkf | |
|
2003-03-10
| ||
| 05:30 | • Ticket [219378ffff]: 1 change artifact: 082c8aa8eb user: dkf | |
|
2003-02-25
| ||
| 16:30 | • Ticket [219378ffff]: 1 change artifact: fa93852240 user: dkf | |
|
2001-04-04
| ||
| 04:57 | • Ticket [219378ffff]: 2 changes artifact: 59448dd6c4 user: dgp | |
|
2001-02-26
| ||
| 18:48 | • Ticket [219378ffff]: 1 change artifact: ed816e419d user: dkf | |
|
2001-02-15
| ||
| 23:30 | • Ticket [219378ffff]: 1 change artifact: f0368cc15e user: dkf | |
|
2001-02-07
| ||
| 23:07 | • Ticket [219378ffff]: 1 change artifact: 787d95885c user: dkf | |
|
2000-12-06
| ||
| 17:36 | • Ticket [219378ffff]: 4 changes artifact: e4a4a016df user: dkf | |
| 14:27 | • Ticket [219378ffff]: 4 changes artifact: b52c11614b user: welch | |
|
2000-12-03
| ||
| 00:59 | • Ticket [219378ffff]: 1 change artifact: 1167b2c683 user: dkf | |
|
2000-11-15
| ||
| 21:49 | • Ticket [219378ffff]: 6 changes artifact: b4f3b0a413 user: dkf | |
|
2000-10-26
| ||
| 05:11 | • New ticket [219378ffff]. artifact: 2b003bcc54 user: nobody | |
[string range] to take index list
Closed / Out of Date219378ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 17 years ago
Descriptionplain2000-10-26 05:11:51
OriginalBugID: 6023 RFE
Version: 8.3.1
SubmitDate: '2000-07-19'
LastModified: '2000-10-25'
Severity: LOW
Status: UnAssn
Submitter: techsupp
OS: Macintosh
OSVersion: linuxppc linux-kernel 2.2.14pre9 (will be MacOS-X :-)
Machine: Macintosh Blue G3
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'
Name:
Maurice Diamantini
Extensions:
nothing
CustomShell:
nothing
DesiredBehavior:
"string range" should accept a list as indices arguments
so the syntaxe could becomme:
string range string first last
instead of simply:
string range string pairList
------------------------------------------------------------
Exemple:
set txt "aaa123bbb679ccc"
set pat {(\d+)\D*(\d+)}
regexp -indices $pat $txt all var1_indexes var2_indexes
# ... drop things made with indices ...
# then get the chunks of txt :
set var1 [string range $txt [lindex $var1_indexes 0] [lindex $var1_indexes 1]]
set var2 [string range $txt [lindex $var2_indexes 0] [lindex $var2_indexes 1]]
As list data type a powerfull feature of the Tcl language,
I'd prefer to be able to write :
set var1 [string range $txt $var1_indexes]
set var2 [string range $txt $var2_indexes]
Or even (if needed)
set varChunk [string range $txt "$var1_indexes $var2_indexes" ]
------------------------------------------------------------
Obiously one can do a proc for it :
## String:range -- return sub-string based on pair list of indices
#
# Do the same as "string range" tcl command, but take a list of
# two indices instead of two indices as parameters
# (then extended to take an arbitrary pair list)
#
# example:
# set txt "aaa123bbb679ccc"
# set pat {(\d+)\D*(\d+)}
# regexp -indices $pat $txt all var1_indexes var2_indexes
# set var1 [String:range $txt $var1_indexes]
# set var2 [String:range $txt $var2_indexes]
# set varChunk [String:range $txt "$var1_indexes $var2_indexes" ]
#
proc String:range {str indices} {
set res ""
foreach {first last} $indices {
append res [string range $str $first $last]
}
set res
}
dkfplain2000-11-15 21:49:56
I'm reluctant to add this sort of thing just here because it is patching a single spot instead of addressing the wider problem of splitting arguments. A general solution so that expansion of lists into several command arguments would be a much more effective use of time...
dkf Ticket [219378ffff]: 1 change
[History diff]2000-12-03 00:59:54
welchplain2000-12-06 14:27:31
The "eval" command provides a general way to split arguments.
eval [list string range $string] $list_of_two_indices
or
eval {string range $string} $list_of_two_indices
I'm inclined to agree with the original request, however, because the the
use of eval may add more overhead than you want with large strings.
It'd be worth measuring the eval approach to see if it's worth a special case.
dkfplain2000-12-06 17:36:06
OK, I think I perhaps ought to explain myself.
Firstly, it is trivially easy to work around this using [foreach], though this is a messy solution, admittedly.
Secondly, the optimal current work-around may well be this:
eval [linsert $list_of_two_indices 0 string range $string]
(It is optimal since it guarantees that there is no real double evaluation of any values, even though it lacks a lot on the "optimality of representation" front too.)
Thirdly, a full solution ought to address the fact that there are many places in Tcl where this sort of conversion of lists to multiple arguments would be useful, and that a more general solution (a la the {expand}$list discussion of a few months back) would be a far more efficient use of people's time than a horde of special fixes scattered throughout Tcl, Tk and all the various extensions. If nothing else, the maintenance overhead is much lower. (Not that I'm advocating a particular syntactic construct here - just the general concept.) Perhaps I ought to go back over that discussion and see if a suitable TIP can be culled from it...? Only problem with doing this is that it results in a shed-load of work falling on me from a great height... :^)
dkf Ticket [219378ffff]: 1 change
[History diff]2001-02-07 23:07:05
dkf Ticket [219378ffff]: 1 change
[History diff]2001-02-15 23:30:02
dkf Ticket [219378ffff]: 1 change
[History diff]2001-02-26 18:48:47
dgp Ticket [219378ffff]: 2 changes
[History diff]2001-04-04 04:57:34
dkf Ticket [219378ffff]: 1 change
[History diff]2003-02-25 16:30:44
dkf Ticket [219378ffff]: 1 change
[History diff]2003-03-10 05:30:01
dkfplain2009-07-14 19:54:51
With Tcl 8.5, it is possible to do:
string range $string {*}$indexPair
The multi-pair case... I think that's uncommon enough that we can simply not handle it.
dkfplain2009-07-14 19:54:52
allow_comments - 1
Log in (anonymous is fine) to add a comment.