summaryrefslogtreecommitdiff
path: root/scratch/fast_split.lua
blob: 0c5ea88a4a73cc50acd1f97d815165aa39201d7a (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
25
26
27
28
local test_line = "/home/tj/hello/world.lua"

local function fast_split(line, split)
  -- local split_line = vim.split(line, split)
  local areas = {}

  local processed = 1
  local line_length = #line + 1

  local part, start
  repeat
    start = string.find(line, split, processed, true) or line_length
    part = string.sub(line, processed, start - 1)

    if start - processed > 0 then
      table.insert(areas, {
        word = part,
        offset = processed
      })
    end

    processed = start + 1
  until start == line_length

  return areas
end

print(vim.inspect(fast_split(test_line, '/')))