lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sun, Mar 2, 2014 at 10:56 AM, Coroutines <> wrote:
> On Sun, Mar 2, 2014 at 12:18 AM, Dirk Laurie <> wrote:
>> 2014-03-02 9:06 GMT+02:00 Coroutines <>:
>>> This does not:
>>>> = string.find('cat', 'cat', -31, true)
>>> 1 3
>>> I expect it to match the string at the index I passed to it, not
>>> silently reposition the start at a valid index (1).
>> All the string functions do that. It is documented under string.sub.
>> | If, after the translation of negative indices, i is less than 1, it
>> is corrected to 1.
> Yes :-)  I believe it makes sense for string.sub(), as you would want
> the valid portion of the string from (let's say) -31 to 5.  This would
> be readjusted to only "sub out" indexes 1 through 5.  I do not believe
> it makes sense for string.find()/string.match() -- as false-positives
> are possible when I tell it to match somewhere clearly before the
> string (in a place it doesn't exist).

My understanding is that when using string.sub(), you want the union
of the indexes you pass and the valid indexes of that string (the
start and end).  I think string.sub() (for a negative index) is
correct, but string.find/match() are not correct.

Also, modifying str_find_aux() to be correct would not affect