Fix problem in regex.gsub

The local n was not initialized and the "string" argument was shadowing the Lua's "string" module.
This commit is contained in:
Francesco Abbate 2021-05-07 10:44:38 +02:00
parent a100a7b6a9
commit ba48cb1382
1 changed files with 4 additions and 3 deletions

View File

@ -35,10 +35,11 @@ end
-- transformations and stuff in lua. Currently, this takes group replacements
-- as \1 - \9.
-- Should work on UTF-8 text.
regex.gsub = function(pattern_string, string, replacement)
regex.gsub = function(pattern_string, str, replacement)
local pattern = type(pattern_string) == "table" and
pattern_string or regex.compile(pattern_string)
local result, str, indices, n = "", string
local result, indices = ""
local n = 0
repeat
indices = { regex.cmatch(pattern, str) }
if #indices > 0 then