summaryrefslogtreecommitdiff
path: root/script/parser/lines.lua
blob: 964aabf41c577823e814c19bb0c48b8522795424 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local sfind = string.find
local ssub  = string.sub

---@param text string
return function (text)
    local current = 1
    local lines = {}
    lines[0] = 1
    local i = 0
    while true do
        local pos = sfind(text,'[\r\n]', current)
        if not pos then
            break
        end
        i = i + 1
        if ssub(text, pos, pos + 1) == '\r\n' then
            current = pos + 2
        else
            current = pos + 1
        end
        lines[i] = current
    end
    return lines
end