mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
Merge branch 'text-split-perf' of https://github.com/payonel/OpenComputers into master-MC1.7.10
This commit is contained in:
commit
54de3fe89d
@ -118,31 +118,42 @@ function text.removeEscapes(txt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
function --[[@delayloaded-start@]] text.split(input, delimiters, dropDelims, di)
|
||||||
function --[[@delayloaded-start@]] text.split(input, delimiters, dropDelims)
|
|
||||||
checkArg(1, input, "string")
|
checkArg(1, input, "string")
|
||||||
checkArg(2, delimiters, "table")
|
checkArg(2, delimiters, "table")
|
||||||
checkArg(3, dropDelims, "boolean", "nil")
|
checkArg(3, dropDelims, "boolean", "nil")
|
||||||
|
checkArg(4, di, "number", "nil")
|
||||||
|
|
||||||
local input_table = text.internal.table_view(input)
|
if #input == 0 then return {} end
|
||||||
local delim_table = tx.select(delimiters, function(e,i,t)
|
di = di or 1
|
||||||
return text.internal.table_view(e)
|
local result = {input}
|
||||||
end)
|
if di > #delimiters then return result end
|
||||||
local parts = tx.partition(input_table, function(e,i,t)
|
|
||||||
local ns, ne = tx.first(t,delim_table,i)
|
local function add(part, index, r, s, e)
|
||||||
if not ns or dropDelims or ns == i then
|
local sub = part:sub(s,e)
|
||||||
return ns, ne
|
if #sub == 0 then return index end
|
||||||
else -- not droping delims and ns>i
|
local subs = r and text.split(sub,delimiters,dropDelims,r) or {sub}
|
||||||
return i, ns-1
|
for i=1,#subs do
|
||||||
|
table.insert(result, index+i-1, subs[i])
|
||||||
end
|
end
|
||||||
end, dropDelims)
|
return index+#subs
|
||||||
return tx.select(parts, function(e,i,t)
|
end
|
||||||
local inner = ''
|
|
||||||
tx.foreach(e, function(ee,ii,tt)
|
local i,d=1,delimiters[di]
|
||||||
inner = inner..ee
|
while true do
|
||||||
end)
|
local next = table.remove(result,i)
|
||||||
return inner
|
if not next then break end
|
||||||
end)
|
local si,ei = next:find(d)
|
||||||
|
if si and ei and ei~=0 then -- delim found
|
||||||
|
i=add(next, i, di+1, 1, si-1)
|
||||||
|
i=dropDelims and i or add(next, i, false, si, ei)
|
||||||
|
i=add(next, i, di, ei+1)
|
||||||
|
else
|
||||||
|
i=add(next, i, di+1, 1, #next)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
end --[[@delayloaded-end@]]
|
end --[[@delayloaded-end@]]
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user