我想做的事
我想要做的真的很简单。我想使用 Lua 检查 Plist 文件中的行。
假设如果 Plist 中的一行是<integer>-1.00</integer>
,我需要切断.00
它以使其成为<integer>-1</integer>
。
我做了什么
我使用一个函数来读取整个文件内容并逐行检查和替换。
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
我的问题
有没有更高效、更优雅的方式来完成同样的工作?