From 5efa8f2448c3e710e5dcd2d7a4c0ca959656f2d4 Mon Sep 17 00:00:00 2001 From: Damian Monogue <3660+demonnic@users.noreply.github.com> Date: Wed, 8 Jul 2020 10:29:11 -0400 Subject: [PATCH] Bugfix for string.split with too many characters (#3963) * Allow string.split("my string", "") with strings > 32 characters Co-authored-by: Vadim Peretokin --- src/mudlet-lua/lua/StringUtils.lua | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/mudlet-lua/lua/StringUtils.lua b/src/mudlet-lua/lua/StringUtils.lua index 88b56205075..dff22ee362b 100644 --- a/src/mudlet-lua/lua/StringUtils.lua +++ b/src/mudlet-lua/lua/StringUtils.lua @@ -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