mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
Add shrink program
This commit is contained in:
parent
664ef63455
commit
546ecf39a1
34
shrink.lua
Normal file
34
shrink.lua
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
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') then
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user