[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is there a patch for "str" in "str" expressions?
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: Wed, 15 Jun 2022 07:03:01 +0200
On 15/06/2022 06:15, Flyer31 Test wrote:
If you mean a function like strstr(str, find), which would return you
the position of the substring find in string str, this does NOT exist
in SIMPLE form in Lua string library ... you have to use string.find
or similar for this with such "match pattern".
I must admit that I also do NOT like this very much ... when I made my
own "static string lib" for minumum RAM requirement Lua (< 40-60kB Lua
stack), I also added such a "simple find function" similar to strstr.
On Tue, Jun 14, 2022 at 1:46 AM Ryan Starrett <pyryanggg@gmail.com> wrote:
Subject, basically. It's similar to the behavior found in Python, I'm just curious if there's an existing patch for it. Otherwise, are there resources that can help me make one?
I don't know Python, but isn't the fourth argument of string.find just
for that? That is:
string.find(str, substring, 1, true ) --> i_start, i_end
Where i_start and i_end are the indexes of the start and end of
substring inside str (without using pattern matching).
Lua Manual (5.3) excerpt:
----------------------------------------------------------------------
Looks for the first match of pattern (see §6.4.1) in the string s. If it
finds a match, then find returns the indices of s where this occurrence
starts and ends; otherwise, it returns nil. A third, optional numeric
argument init specifies where to start the search; its default value is
1 and can be negative. A value of true as a fourth, optional argument
plain turns off the pattern matching facilities, so the function does a
plain "find substring" operation, with no characters in pattern being
considered magic. Note that if plain is given, then init must be given
as well.
----------------------------------------------------------------------
-- Lorenzo