mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +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:
parent
cbafc49e8a
commit
151b57adc6
5
lume.lua
5
lume.lua
@ -176,8 +176,9 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.slice(t, i, j)
|
function lume.slice(t, i, j)
|
||||||
i = i or 1
|
local function index(x) return x < 0 and (#t + x + 1) or x end
|
||||||
j = j and (j < 0 and (#t + j + 1) or j) or #t
|
i = i and index(i) or 1
|
||||||
|
j = j and index(j) or #t
|
||||||
local rtn = {}
|
local rtn = {}
|
||||||
for i = math.max(i, 1), math.min(j, #t) do
|
for i = math.max(i, 1), math.min(j, #t) do
|
||||||
rtn[#rtn + 1] = t[i]
|
rtn[#rtn + 1] = t[i]
|
||||||
|
Loading…
Reference in New Issue
Block a user