What I want to do
What I want to do is really simple. I want use Lua to check lines in a Plist file.
Let's say if a line in Plist, is <integer>-1.00</integer>
, I need to cut the .00
off to make it be <integer>-1</integer>
.
What I did
I use a function to read the whole file content and do line by line check and replace.
local function doLineClean( cont )
newcont = ''
string.gsub( cont, "(.-)\r?\n", function(line)
if string.match( line, "<integer>.-<%/integer>" ) then
string.gsub( line, "<.->(.-)<.->", function(v)
a, b = string.find(v,"%..*")
if a and b then
v = string.sub( v, 0, a - 1 )
end
line = "\t\t<integer>"..v.."</integer>"
end )
end
newcont = newcont .. line .. '\n'
end )
return newcont
end
My question
Is there an more efficient and elegant way to do the same job?