Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2008-12-10
02:10 • Closed ticket [1243354fff]: string first misbehavior plus 4 other changes artifact: d712158b5b user: dgp
02:10 • Ticket [1243354fff]: 4 changes artifact: f72892dacd user: dgp
2008-09-19
02:10 • Ticket [1243354fff]: 4 changes artifact: 7fd474ad0a user: dgp
02:10 • Add attachment 1243354-update.patch to ticket [1243354fffffffff|1243354... artifact: 990fa86f24 user: dgp
2008-08-08
03:24 • Ticket [1243354fff] string first misbehavior status still Open with 4 othe... artifact: d730a7e2f3 user: dgp
2006-04-17
22:46 • Ticket [1243354fff]: 5 changes artifact: 97ebcf410b user: dkf
2005-09-01
21:40 • Ticket [1243354fff]: 4 changes artifact: 5ee6dfaa79 user: dkf
2005-07-23
05:27 • Ticket [1243354fff]: 4 changes artifact: 5444c46c69 user: dgp
05:26 • Ticket [1243354fff]: 4 changes artifact: 5510633959 user: dgp
05:26 • Add attachment 1243354.patch to ticket [1243354fff] artifact: ede22eb0ff user: dgp
05:26 • Ticket [1243354fff] string first misbehavior status still Open with 4 othe... artifact: d262840fd9 user: dgp
05:26 • Ticket [1243354fff]: 4 changes artifact: ba8657821e user: dgp
05:19 • Ticket [1243354fff]: 5 changes artifact: 591e03b54a user: msofer
05:15 • Ticket [1243354fff]: 5 changes artifact: 64b99332e9 user: hobbs
05:06 • Ticket [1243354fff]: 4 changes artifact: 06bf28e071 user: dgp
2005-07-22
22:06 • New ticket [1243354fff]. artifact: 1cd6478e53 user: dgp

[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: