lua-users home
lua-l archive

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


-- Pierre-Yves


On Mon, Mar 3, 2014 at 6:24 PM, Francisco Olarte <folarte@peoplecall.com> wrote:
> I do not agree. string.find is trying to find AFTER the passed
> position, not AT it, so it has its logic to clip it to 1, it's a
> simple optimization. I.e, string length 5, you pass -7, string cannot
> be found seven chars before the end, because there is no string there,
> try 6 chars before the end, same problem, try 5 chars, now we are
> talking. Clipping to 1 just optimizes out the impossible end. Ie, if
> you tell someone to find 'b' in 'abc' between offsets minus and plus
> infinity, it can be found at 2, and you can clip the bounds to 1..3
> before starting.
>
> Francisco Olarte.

This doesn't hold for anchored patterns.

    p = "^aab"
    s = "aabbaab"
    s:find(p) --> 1, 3
    s:find(p, -4) --> nil
    s:find(p, -30) --> 1, 3 ... Whoops.