function Util.ParseEscapeSequences(m)return((m:gsub("\092\040\046\041",{t="\t",n="\n"})):gsub("\092\117\040\037\120\037\120\037\120\037\120\041",charCode)):gsub("\092\120\040\037\120\037\120\041",charCode)end function Util.EncodeEscapedOperator(m,t)local l=t:sub(1,1)local e=t:gsub("\046","\037\037\037\049")local N="\037"..l return m:gsub("\040"..(N..("\043\041\040"..(e.."\041"))),function(m,t)return(m:sub(1,#m-1)..t):gsub("\046",function(m)return"\092\117"..string.format("\037\048\052\120",string.byte(m),16)end)end)end local m={"\038\038";"\124\124";"\059"}function Util.EncodeEscapedOperators(t)for m,l in ipairs(m)do t=Util.EncodeEscapedOperator(t,l)end return t end local function t(m)return(((m:gsub("\092\092","\095\095\095\033\067\077\068\082\095\069\083\067\065\080\069\033\095\095\095")):gsub("\092\"","\095\095\095\033\067\077\068\082\095\081\085\079\084\069\033\095\095\095")):gsub("\092\'","\095\095\095\033\067\077\068\082\095\083\081\085\079\084\069\033\095\095\095")):gsub("\092\n","\095\095\095\033\067\077\068\082\095\078\076\033\095\095\095")end local function l(m)return((m:gsub("\095\095\095\033\067\077\068\082\095\069\083\067\065\080\069\033\095\095\095","\092")):gsub("\095\095\095\033\067\077\068\082\095\081\085\079\084\069\033\095\095\095","\"")):gsub("\095\095\095\033\067\077\068\082\095\078\076\033\095\095\095","\n")end

function Util.ParseEscapeSequences(text)
	return text:gsub("\\(.)", {
		t = "\t";
		n = "\n";
	})
	:gsub("\\u(%x%x%x%x)", charCode)
	:gsub("\\x(%x%x)", charCode)
end

function Util.EncodeEscapedOperator(text, op)
	local first = op:sub(1, 1)
	local escapedOp = op:gsub(".", "%%%1")
	local escapedFirst = "%" .. first

	return text:gsub("(" .. escapedFirst .. "+)(" .. escapedOp .. ")", function(esc, op)
			return (esc:sub(1, #esc-1) .. op):gsub(".", function(char)
					return "\\u" .. string.format("%04x", string.byte(char), 16)
			end)
	end)
end

local OPERATORS = {"&&", "||", ";"}
function Util.EncodeEscapedOperators(text)
	for _, operator in ipairs(OPERATORS) do
		text = Util.EncodeEscapedOperator(text, operator)
	end

	return text
end

local function encodeControlChars(text)
	return (
		text
		:gsub("\\\\", "___!CMDR_ESCAPE!___")
		:gsub("\\\"", "___!CMDR_QUOTE!___")
		:gsub("\\'", "___!CMDR_SQUOTE!___")
		:gsub("\\\n", "___!CMDR_NL!___")
	)
end

local function decodeControlChars(text)
	return (
		text
		:gsub("___!CMDR_ESCAPE!___", "\\")
		:gsub("___!CMDR_QUOTE!___", "\"")
		:gsub("___!CMDR_NL!___", "\n")
	)
end
