Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lua/richclip/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ end

---Separate string into lines
UTILS.str_to_lines = function(str)
local result = {}
for line in str:gmatch '[^\n\r]+' do
table.insert(result, line)
end
return result
-- TODO: This feels slow
str = str:gsub("\r\n", "\n")
str = str:gsub("\r", "\n")
return vim.split(str, "\n")
end

---Combines lines into a single string
Expand Down
6 changes: 5 additions & 1 deletion tests/spec/utils_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("ser tests", function()

str = ""
lines = utils.str_to_lines(str)
assert.same(lines, {})
assert.same(lines, {""})

str = "a\rb"
lines = utils.str_to_lines(str)
Expand All @@ -39,6 +39,10 @@ describe("ser tests", function()
str = "a\r\nb"
lines = utils.str_to_lines(str)
assert.same(lines, { "a", "b" })

str = "a\n\nb"
lines = utils.str_to_lines(str)
assert.same(lines, { "a", "", "b" })
end)

it('lines_to_str', function()
Expand Down