Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a splitString funtion to textutils #1768

Open
wants to merge 10 commits into
base: mc-1.20.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,32 @@ function urlEncode(str)
return str
end

--- Splits a string in a table.
--
-- @tparam string string_to_split The string to split.
-- @tparam string pattern At what pattern to split the string.
-- @treturn table A table containing the splitted strings.
-- @usage args = textutils.splitString("arg1 arg2", " ")
-- @since edit this if it goes live (I hope it does)
local function split(string_to_split, pattern)
tkbstudios marked this conversation as resolved.
Show resolved Hide resolved
local Table = {}
tkbstudios marked this conversation as resolved.
Show resolved Hide resolved
local fpat = "(.-)" .. pattern
local last_end = 1
local s, e, cap = string_to_split:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table, cap)
end
last_end = e + 1
s, e, cap = string_to_split:find(fpat, last_end)
end
if last_end <= #string_to_split then
cap = string_to_split:sub(last_end)
table.insert(Table, cap)
end
return Table
end
tkbstudios marked this conversation as resolved.
Show resolved Hide resolved

local tEmpty = {}

--- Provides a list of possible completions for a partial Lua expression.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ textutils.serialize( table )
textutils.unserialize( string )
textutils.serializeJSON( table, [useNBTStyle] )
textutils.urlEncode( string )
textutils.splitString( string, string )
tkbstudios marked this conversation as resolved.
Show resolved Hide resolved
textutils.complete( string, table )
Loading