[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: extension to string.gmatch (structural regular expressions)
- From: Shmuel Zeigerman <shmuz@...>
- Date: Fri, 04 Jan 2008 12:01:42 +0200
Javier Guerra wrote:
On 1/3/08, Duncan Cross <duncan.cross@gmail.com> wrote:
Here's a first attempt at a splitting gmatch:
here's one of the best... this is a recurring thread!
http://lua-users.org/lists/lua-l/2006-12/msg00414.html
It seems, Rici's function can be further simplified by not passing
'self' around:
function string:split(pat)
local st, g = 1, self:gmatch("()("..pat..")")
local function getter(segs, seps, sep, cap1, ...)
st = sep and seps + #sep
return self:sub(segs, (seps or 0) - 1), cap1 or sep, ...
end
return function()
if st then return getter(st, g()) end
end
end
--
Shmuel