diff options
author | Thijs <thijs@thijsschreijer.nl> | 2022-01-05 22:35:30 +0300 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2022-01-05 22:52:22 +0300 |
commit | 585f0c5e98e19b2ca19bf8138b518c58198c0c09 (patch) | |
tree | 919a772aa6db25907d763a45827c462f7f22d71d /lua | |
parent | 98cb7f4a4f035595b9f794fed44b4f30f86b956e (diff) |
fix(stringx) expandtabs failed on Lua 5.3+
Diffstat (limited to 'lua')
-rw-r--r-- | lua/pl/stringx.lua | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lua/pl/stringx.lua b/lua/pl/stringx.lua index 8454f08..8ba6763 100644 --- a/lua/pl/stringx.lua +++ b/lua/pl/stringx.lua @@ -210,10 +210,14 @@ end -- @usage stringx.expandtabs('\tone,two,three', 4) == ' one,two,three' -- @usage stringx.expandtabs(' \tone,two,three', 4) == ' one,two,three' function stringx.expandtabs(s,tabsize) - assert_string(1,s) - tabsize = tabsize or 8 - return (s:gsub("([^\t\r\n]*)\t", function(before_tab) + assert_string(1,s) + tabsize = tabsize or 8 + return (s:gsub("([^\t\r\n]*)\t", function(before_tab) + if tabsize == 0 then + return before_tab + else return before_tab .. (" "):rep(tabsize - #before_tab % tabsize) + end end)) end |