OpenComputerScripts/shrink.lua

38 lines
989 B
Lua
Raw Normal View History

-- Shrink
-- Created by Kiritow
2018-11-27 23:26:20 +08:00
local function shrink(source)
local len=string.len(source)
local qouted=nil
local last_space=false
local output=''
for i=1,len do
local this=string.sub(source,i,i)
if(not qouted) then
if(this=='"' or this=="'") then
qouted=this
last_space=false
output=output .. this
elseif(this==' ' or this=='\n' or this=='\r' or this=='\t') then
2018-11-27 23:26:20 +08:00
if(not last_space) then
last_space=true
output=output .. ' '
end
else
last_space=false
output=output .. this
end
else
if(this==qouted) then
qouted=nil
last_space=false
output=output .. this
else
output=output .. this
end
end
end
return output
end
return shrink