From 72855318705dbee17e3aacc63958ca01e7b72d3c Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Tue, 20 Sep 2022 15:00:44 +1000 Subject: [PATCH] fixed dedent() with trimmed blank lines (some editors do this automatically) --- stringx.lua | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/stringx.lua b/stringx.lua index f9d2e81..cda2f26 100644 --- a/stringx.lua +++ b/stringx.lua @@ -192,16 +192,18 @@ function stringx.deindent(s, keep_trailing_empty) --de-indent the lines local res = {} for _, line in ipairs(lines) do - local line_start = line:sub(1, indent:len()) - local start_len = line_start:len() - if - line_start == indent - or ( - start_len < indent_len - and line_start == indent:sub(1, start_len) - ) - then - line = line:sub(start_len + 1) + if line ~= "" then + local line_start = line:sub(1, indent:len()) + local start_len = line_start:len() + if + line_start == indent + or ( + start_len < indent_len + and line_start == indent:sub(1, start_len) + ) + then + line = line:sub(start_len + 1) + end end table.insert(res, line) end