Menu

#3192 [string first] misbehavior

obsolete: 8.5a4
closed-rejected
5
2008-12-09
2005-07-22
Don Porter
No

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.

Discussion

  • Jeffrey Hobbs

    Jeffrey Hobbs - 2005-07-22
    • status: open --> open-wont-fix
     
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2005-07-22

    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.

     
  • miguel sofer

    miguel sofer - 2005-07-22
    • status: open-wont-fix --> open
     
  • miguel sofer

    miguel sofer - 2005-07-22

    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. "

     
  • Don Porter

    Don Porter - 2005-07-22

    Logged In: YES
    user_id=80530

    FWIW, this updated patch
    fixes the same issue
    in [string last].

     
  • Don Porter

    Don Porter - 2005-07-22
     
  • Don Porter

    Don Porter - 2005-07-22

    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.

     
  • Donal K. Fellows

    Logged In: YES
    user_id=79902

    Note that strstr() finds the empty needle at the start of
    the haystack.

     
  • Donal K. Fellows

    • assigned_to: dkf --> hobbs
     
  • Donal K. Fellows

    Logged In: YES
    user_id=79902

    Assigning to person made nervous by the thought of fixing it...

     
  • Don Porter

    Don Porter - 2008-08-07

    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.

     
  • Don Porter

    Don Porter - 2008-09-18
     
  • Don Porter

    Don Porter - 2008-09-18

    New patch makes the [string first]
    and [string last] change for
    testing.

    File Added: 1243354-update.patch

     
  • Don Porter

    Don Porter - 2008-12-09

    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.

     
  • Don Porter

    Don Porter - 2008-12-09
    • assigned_to: hobbs --> dgp
    • status: open --> closed-rejected
     
MongoDB Logo MongoDB