[string first] misbehavior
Closed / Rejected1243354fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 18 years ago
Descriptionplain2005-07-22 22:06:43
I'd be happier with [string first] if
it were a true substring finder, but
it fails that task finding empty
strings:
% string first {} xyz
-1
Here's a patch to make
[string first] behave as I prefer.
dgpplain2005-07-23 05:06:43
File Added - 142950: stringfirst.patch
hobbsplain2005-07-23 05:15:13
Logged In: YES
user_id=72656
This proposed change makes me nervous ... this behavior has
been in Tcl forever:
tellar [~] 115 > tclsh7.6
% string first {} abc
-1
and I'd leave it that way, but clarify in the docs.
msoferplain2005-07-23 05:19:49
Logged In: YES user_id=148712 IMO, this patch also requires patching the manual page. "Search string2 for a sequence of characters that exactly match the characters in string1. If found, return the index of the first character in the first such match within string2. " should be changed, maybe to "Search string2 for a substring that exactly matches string1. If found, return the starting index of the first such match within string2. "
dgpplain2005-07-23 05:26:27
Logged In: YES user_id=80530 FWIW, this updated patch fixes the same issue in [string last].
dgpplain2005-07-23 05:26:28
File Added - 142951: 1243354.patch
dgpplain2005-07-23 05:26:29
File Deleted - 142950:
dgpplain2005-07-23 05:27:47
Logged In: YES user_id=80530 Also, FWIW, this "feature" of [string first] and [string last] not being able to find empty substrings may be related to the "feature" of [string replace] that it cannot replace empty substrings.
dkfplain2005-09-01 21:40:39
Logged In: YES user_id=79902 Note that strstr() finds the empty needle at the start of the haystack.
dkfplain2006-04-17 22:46:13
Logged In: YES user_id=79902 Assigning to person made nervous by the thought of fixing it...
dgpplain2008-08-08 03:24:52
Logged In: YES
user_id=80530
Originator: YES
Related regexp bug:
kbk% regexp -all -indices -inline -- {} foo
{0 -1} {1 0} {2 1}
kbkbut not {3 2}
kbkFWIW: % regexp -all -indices -inline -- {$} foo
{3 2}
kbkso it *can* match an empty substring at the end... but *doesn't* for an empty needle.
dgpplain2008-09-19 02:10:44
File Added - 293917: 1243354-update.patch New patch makes the [string first] and [string last] change for testing. File Added: 1243354-update.patch
dgpplain2008-12-10 02:10:16
This was attempted as part of TIP 323, but was found to be too disruptive to expectations of existing code. If a substring finder is needed, a new command will have to be employed for that purpose.
dgp Closed ticket [1243354fff].
[History diff]2008-12-10 02:10:20
Log in (anonymous is fine) to add a comment.
Attachments:
- 1243354-update.patch [download] added by dgp on 2008-09-19 02:10:43. [details]
- 1243354.patch [download] added by dgp on 2005-07-23 05:26:28. [details]