Skip to content

Commit

Permalink
Bugfix for string.split with too many characters (Mudlet#3963)
Browse files Browse the repository at this point in the history
* Allow string.split("my string", "") with strings > 32 characters
Co-authored-by: Vadim Peretokin <vperetokin@gmail.com>
  • Loading branch information
demonnic authored Jul 8, 2020
1 parent f87196c commit 5efa8f2
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/mudlet-lua/lua/StringUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,22 @@ end
--- Documentation: https://wiki.mudlet.org/w/Manual:String_Functions#string.split
function string:split(delimiter)
delimiter = delimiter or " "
if delimiter == "" then return {self:match( (self:gsub(".", "(.)")) )} end
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from, delim_from - 1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )

if delimiter == "" then
for i = 1, #self do
result[i] = self:sub(i,i)
end
else
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
result[#result+1] = string.sub(self, from, delim_from - 1)
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
result[#result+1] = string.sub(self, from)
end
table.insert( result, string.sub( self, from ) )
return result
end

Expand Down

0 comments on commit 5efa8f2

Please sign in to comment.