Skip to content

Commit

Permalink
Split
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Jan 29, 2019
1 parent 25d33f7 commit 5075264
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions kt/scripts/kt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,35 @@ function hx_query(inmap, outmap)
end


-- Python-like string split, with proper handling of edge-cases.
function nsplit(s, delim, n)
n = n or -1
local pos, length = 1, #s
local parts = {}
while n ~= 0 and pos do
local dstart, dend = string.find(s, delim, pos, true)
local part
if not dstart then
part = string.sub(s, pos)
pos = nil
elseif dend < dstart then
part = string.sub(s, pos, dstart)
if dstart < length then
pos = dstart + 1
else
pos = nil
end
else
part = string.sub(s, pos, dstart - 1)
pos = dend + 1
end
table.insert(parts, part)
n = n - 1
end
return parts
end


-- get luajit version.
function jit_version(inmap, outmap)
outmap.version = "v" .. jit.version
Expand Down

0 comments on commit 5075264

Please sign in to comment.