Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Add string:split() #192

Closed
wants to merge 4 commits into from
Closed
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
11 changes: 3 additions & 8 deletions lib/libs/string.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
local rbxString = {}

for key, value in pairs(string) do
rbxString[key] = value
end

rbxString.split = function(str, sep)
-- luacheck: ignore 1
string.split = function(str, sep)
local result = {}

if sep == "" then
Expand Down Expand Up @@ -33,4 +28,4 @@ rbxString.split = function(str, sep)
return result
end

return rbxString
return string
4 changes: 4 additions & 0 deletions lib/libs/string_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ describe("libs.string", function()
assert.is_function(string.split)
end)

it("should work as a string method", function()
assert.is_function(("").split)
end)

it("should return an array of comma separated strings if sep is nil", function()
assert.are.same({"Hello", "world", "and", "lemur"}, string.split("Hello,world,and,lemur"))
end)
Expand Down