Clean up text.escape_pattern

This commit is contained in:
Lars Mueller 2022-09-28 20:57:24 +02:00
parent e648775cae
commit 715bf47aba

@ -101,24 +101,13 @@ function is_hexadecimal(byte)
return byte >= zero and byte <= nine or byte >= letter_a and byte <= letter_f return byte >= zero and byte <= nine or byte >= letter_a and byte <= letter_f
end end
magic_chars = { magic_charset = "[" .. ("%^$+-*?.[]()"):gsub(".", "%%%1") .. "]"
"%",
"(",
")",
".",
"+",
"-",
"*",
"?",
"[",
"^",
"$"
}
local magic_charset = {}
for _, magic_char in pairs(magic_chars) do table.insert(magic_charset, "%" .. magic_char) end
magic_charset = "[" .. table.concat(magic_charset) .. "]"
function escape_magic_chars(text) return text:gsub("(" .. magic_charset .. ")", "%%%1") end function escape_pattern(text)
return text:gsub(magic_charset, "%%%1")
end
escape_magic_chars = escape_pattern
local keywords = modlib.table.set{"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while"} local keywords = modlib.table.set{"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while"}
keywords["goto"] = true -- Lua 5.2 (LuaJIT) support keywords["goto"] = true -- Lua 5.2 (LuaJIT) support