Ticket UUID: | 1243354 | |||
Title: | [string first] misbehavior | |||
Type: | Bug | Version: | obsolete: 8.5a4 | |
Submitter: | dgp | Created on: | 2005-07-22 22:06:43 | |
Subsystem: | 18. Commands M-Z | Assigned To: | dgp | |
Priority: | 5 Medium | Severity: | ||
Status: | Closed | Last Modified: | 2008-12-10 02:10:20 | |
Resolution: | Rejected | Closed By: | dgp | |
Closed on: | 2008-12-09 19:10:20 | |||
Description: |
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. | |||
User Comments: |
dgp added on 2008-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 added on 2008-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 dgp added on 2008-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. dkf added on 2006-04-17 22:46:13: Logged In: YES user_id=79902 Assigning to person made nervous by the thought of fixing it... dkf added on 2005-09-01 21:40:39: Logged In: YES user_id=79902 Note that strstr() finds the empty needle at the start of the haystack. dgp added on 2005-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. dgp added on 2005-07-23 05:26:29: File Deleted - 142950: dgp added on 2005-07-23 05:26:28: File Added - 142951: 1243354.patch dgp added on 2005-07-23 05:26:27: Logged In: YES user_id=80530 FWIW, this updated patch fixes the same issue in [string last]. msofer added on 2005-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. " hobbs added on 2005-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. dgp added on 2005-07-23 05:06:43: File Added - 142950: stringfirst.patch |