mirror of
https://github.com/TangentFoxy/lume.git
synced 2025-07-28 02:52:21 +00:00
Fixed behaviour for negative i argument on lume.slice()
A negative value for the `i` argument of lume.slice() is now handled properly (used as an index from the end of the string) to mimicing the behaviour of lua's string.sub()
This commit is contained in:
5
lume.lua
5
lume.lua
@@ -176,8 +176,9 @@ end
|
||||
|
||||
|
||||
function lume.slice(t, i, j)
|
||||
i = i or 1
|
||||
j = j and (j < 0 and (#t + j + 1) or j) or #t
|
||||
local function index(x) return x < 0 and (#t + x + 1) or x end
|
||||
i = i and index(i) or 1
|
||||
j = j and index(j) or #t
|
||||
local rtn = {}
|
||||
for i = math.max(i, 1), math.min(j, #t) do
|
||||
rtn[#rtn + 1] = t[i]
|
||||
|
Reference in New Issue
Block a user