Skip to content

Commit

Permalink
feat(util): fast plain text split
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 30, 2024
1 parent 6d9a0ba commit 6a30aec
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lua/trouble/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ end

---@param s string
function M.lines(s)
return M.split(s, "\n")
end

---@param s string
---@param c? string
function M.split(s, c)
c = c or "\n"
local pos = 1
local l = 0
return function()
Expand All @@ -176,7 +183,7 @@ function M.lines(s)
end
l = l + 1

local nl = s:find("\n", pos, true)
local nl = s:find(c, pos, true)
if not nl then
local lastLine = s:sub(pos)
pos = -1
Expand Down

0 comments on commit 6a30aec

Please sign in to comment.