function Util.SplitString(u,t)u=encodeControlChars(u)t=t or math.huge local P={}local U,b="\094\040\091\'\"\093\041","\040\091\'\"\093\041\036"local q,T for u in u:gmatch("\091\094 \093\043")do u=Util.ParseEscapeSequences(u)local x=u:match(U)local k=u:match(b)local E=u:match("\040\092\042\041\091\'\"\093\036")if x and(not T and not k)then q,T=u,x elseif q and(k==T and#E%2==0)then u,q,T=q..(" "..u),nil,nil elseif q then q=q..(" "..u)end if not q then P[#P+(#P>t and 0 or 1)]=decodeControlChars((u:gsub(U,"")):gsub(b,""))end end if q then P[#P+(#P>t and 0 or 1)]=decodeControlChars(q)end return P end

function Util.SplitString(text, max)
	text = encodeControlChars(text)
	max = max or math.huge
	local t = {}
	local spat, epat = [=[^(['"])]=], [=[(['"])$]=]
	local buf, quoted
	for str in text:gmatch("[^ ]+") do
		str = Util.ParseEscapeSequences(str)
		local squoted = str:match(spat)
		local equoted = str:match(epat)
		local escaped = str:match([=[(\*)['"]$]=])
		if squoted and not quoted and not equoted then
			buf, quoted = str, squoted
		elseif buf and equoted == quoted and #escaped % 2 == 0 then
			str, buf, quoted = buf .. " " .. str, nil, nil
		elseif buf then
			buf = buf .. " " .. str
		end
		if not buf then
			t[#t + (#t > max and 0 or 1)] = decodeControlChars(str:gsub(spat, ""):gsub(epat, ""))
		end
	end

	if buf then
		t[#t + (#t > max and 0 or 1)] = decodeControlChars(buf)
	end

	return t
end
