lua-users home
lua-l archive

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


On Sun, Mar 2, 2014 at 8:21 PM, Coroutines <> wrote:
> I was attempting to do a plain-match from index -31 (an index I said I
> cannot predict, -31 is just an example).  I do understand how to use
> the pattern matching facilities, I am saying that if the index is
> before the string it should not be corrected to be 1, it should not be
> silently corrected to be a valid index.  If the starting index is
> after the string nil is returned because it cannot match a string that
> doesn't exist at that point.  The same should be true if the index is
> before the string.

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.