simplify split function for our usecase
This commit is contained in:
parent
6651949665
commit
2df1d2f52d
15
lcd.lua
15
lcd.lua
|
@ -32,13 +32,16 @@ local CHAR_WIDTH = 5
|
||||||
|
|
||||||
local split = function(s, pat)
|
local split = function(s, pat)
|
||||||
-- adapted from https://stackoverflow.com/a/1647577/4067384
|
-- adapted from https://stackoverflow.com/a/1647577/4067384
|
||||||
pat = pat or '%s+'
|
-- simplified for our only usecase
|
||||||
local st, g = 1, string.gmatch(s, "()("..pat..")")
|
local st, g = 1, s:gmatch("()("..pat..")")
|
||||||
local function getter(segs, seps, sep, cap1, ...)
|
local function getter()
|
||||||
st = sep and seps + #sep
|
if st then
|
||||||
return string.sub(s, segs, (seps or 0) - 1), cap1 or sep, ...
|
local segs, seps, sep = st, g()
|
||||||
|
st = sep and seps + #sep
|
||||||
|
return s:sub(segs, (seps or 0) - 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return function() if st then return getter(st, g()) end end
|
return getter
|
||||||
end
|
end
|
||||||
|
|
||||||
local create_lines = function(text)
|
local create_lines = function(text)
|
||||||
|
|
Loading…
Reference in New Issue