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. "
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
kbk % regexp -all -indices -inline -- {} foo
{0 -1} {1 0} {2 1}
kbk but not {3 2}
kbk FWIW: % regexp -all -indices -inline -- {$} foo
{3 2}
kbk so it *can* match an empty substring at the end... but *doesn't* for an empty needle.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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. "
Logged In: YES
user_id=80530
FWIW, this updated patch
fixes the same issue
in [string last].
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.
Logged In: YES
user_id=79902
Note that strstr() finds the empty needle at the start of
the haystack.
Logged In: YES
user_id=79902
Assigning to person made nervous by the thought of fixing it...
Logged In: YES
user_id=80530
Originator: YES
Related regexp bug:
kbk % regexp -all -indices -inline -- {} foo
{0 -1} {1 0} {2 1}
kbk but not {3 2}
kbk FWIW: % regexp -all -indices -inline -- {$} foo
{3 2}
kbk so it *can* match an empty substring at the end... but *doesn't* for an empty needle.
New patch makes the [string first]
and [string last] change for
testing.
File Added: 1243354-update.patch
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.