[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua Suggestion: return nil in string.find/match() for indexes that are before the string
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Tue, 4 Mar 2014 15:36:34 +0100
On Tue, Mar 4, 2014 at 10:01 AM, Francisco Olarte
<folarte@peoplecall.com> wrote:
> Hi:
>
>
> On Mon, Mar 3, 2014 at 9:53 PM, Pierre-Yves Gérardy <pygy79@gmail.com> wrote:
>> 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
> ...
>> 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.
>
> Would you care to elaborate?
s:find(p, -3) --> 5, 7
> To me your example seems to demonstrate
> it holds ( first one ok, second one does not find it as you cannot
> find a start of string between 4 chars before the end of a 7 char
> string and the end, third one finds it as I said. You tell it to find
> a start of string between 30 chars before the end ( 23 chars before
> the start ) and the end and it finds it at the start.
"^" triggers a search anchored to the index, not the start of the string.
You said that skipping negative indices was a correct optimization,
that's true for "free roaming" patterns, but it doesn't hold if they
are anchored. There's nothing to find anchored to an index smaller
than 1.
-- Pierre-Yves