function Util.SubstituteArgs(Q,x)Q=encodeCommandEscape(Q)if type(x)=="\116\097\098\108\101"then for Q=1,#x,1 do local H=tostring(Q)x[H]=x[Q]if x[H]:find("\037\115")then x[H]=string.format("\037\113",x[H])end end end return decodeCommandEscape(Q:gsub("\036\040\037\119\043\041",x))end
--- Replaces arguments in the format $1, $2, $something with whatever the
-- given function returns for it.
function Util.SubstituteArgs(str, replace)
	str = encodeCommandEscape(str)
	-- Convert numerical keys to strings
	if type(replace) == "table" then
		for i = 1, #replace do
			local k = tostring(i)
			replace[k] = replace[i]

			if replace[k]:find("%s") then
				replace[k] = string.format("%q", replace[k])
			end
		end
	end
	return decodeCommandEscape(str:gsub("$(%w+)", replace))
end
