[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua Suggestion: return nil in string.find/match() for indexes that are before the string
- From: Pierre-Yves Gérardy <pygy79@...>
- Date: Mon, 3 Mar 2014 21:53:40 +0100
On Mon, Mar 3, 2014 at 6:24 PM, Francisco Olarte <firstname.lastname@example.org> 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.