mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 22:24:35 +00:00
fixed dedent() with trimmed blank lines (some editors do this automatically)
This commit is contained in:
parent
662101ddae
commit
7285531870
22
stringx.lua
22
stringx.lua
@ -192,16 +192,18 @@ function stringx.deindent(s, keep_trailing_empty)
|
|||||||
--de-indent the lines
|
--de-indent the lines
|
||||||
local res = {}
|
local res = {}
|
||||||
for _, line in ipairs(lines) do
|
for _, line in ipairs(lines) do
|
||||||
local line_start = line:sub(1, indent:len())
|
if line ~= "" then
|
||||||
local start_len = line_start:len()
|
local line_start = line:sub(1, indent:len())
|
||||||
if
|
local start_len = line_start:len()
|
||||||
line_start == indent
|
if
|
||||||
or (
|
line_start == indent
|
||||||
start_len < indent_len
|
or (
|
||||||
and line_start == indent:sub(1, start_len)
|
start_len < indent_len
|
||||||
)
|
and line_start == indent:sub(1, start_len)
|
||||||
then
|
)
|
||||||
line = line:sub(start_len + 1)
|
then
|
||||||
|
line = line:sub(start_len + 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
table.insert(res, line)
|
table.insert(res, line)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user