awsdert
Newcomer
- Joined
- Apr 7, 2022
- Messages
- 11
- Reaction score
- 0
Since I know the rest of the functions work as intended (including the public patsubst function which calls this internally) I can only view this new version of the replacement loop as the culprit for the infinite loop, any ideas where I'm going wrong?
Code:
-- internal replacement function
local function rpatsubst( match, subst, arg )
local swapped = true
local i, e, tmp
-- lua modifies the source by default, try to indicate a copy is wanted
arg = '' .. arg
while swapped == true do
swapped = false
for e = #arg, 0, -1 do
-- Going backwards makes it easier to catch things like
-- a(b(c)) which if traversed forwards would only work
-- if there are no sub instances or on the 1st "instance" (b(c)
for i = #arg, 0, -1 do
tmp = matches( match, arg:sub(i,e) )
if tmp then
local pfx = (arg:sub(1,-i) or '')
local sfx = (arg:sub(e+1) or '')
if match.qry == false then
arg = pfx .. subst.all .. sfx
else
arg = pfx .. subst.pfx .. tmp.txt
if subst.sfx ~= '' then
arg = arg .. subst.sfx .. sfx
end
arg = arg .. sfx
end
swapped = true
break
end
end
if swapped == true then break end
end
end
return arg
end