Jump to content

Module:String/charsetEscape: Difference between revisions

From The Mighty Kingdoms Wiki
Template>Theknightwho
No edit summary
 
m 1 revision imported
 
(No difference)

Latest revision as of 08:44, 29 June 2025

Documentation for this module may be created at Module:String/charsetEscape/doc

local gsub = string.gsub

local chars
local function get_chars()
	chars, get_chars = {
		["\000"] = "%z", ["%"] = "%%", ["-"] = "%-", ["]"] = "%]", ["^"] = "%^",
	}, nil
	return chars
end

--[==[Escapes the magic characters used in pattern character sets: {%-]^}, and converts the null character to {%z}.]==]
return function(str)
	return (gsub(str, "[%z%%%-%]^]", chars or get_chars()))
end