feat(utils): add few string utils
This commit is contained in:
parent
d8c9a652ae
commit
d57d5a7c0f
2 changed files with 28 additions and 1 deletions
|
@ -28,5 +28,6 @@ return {
|
|||
math = require(cwd .. "math"),
|
||||
graphics = require(cwd .. "graphics"),
|
||||
filesystem = require(cwd .. "filesystem"),
|
||||
table = require(cwd .. "table")
|
||||
table = require(cwd .. "table"),
|
||||
string = require(cwd .. "string")
|
||||
}
|
||||
|
|
26
sonic-radiance.love/core/utils/string.lua
Normal file
26
sonic-radiance.love/core/utils/string.lua
Normal file
|
@ -0,0 +1,26 @@
|
|||
local String = {}
|
||||
|
||||
function String.isEmpty(pString)
|
||||
return (pString == "" or pString == nil)
|
||||
end
|
||||
|
||||
function String.split(pString, pPattern)
|
||||
local Table = {} -- NOTE: use {n = 0} in Lua-5.0
|
||||
local fpat = "(.-)" .. pPattern
|
||||
local last_end = 1
|
||||
local s, e, cap = pString:find(fpat, 1)
|
||||
while s do
|
||||
if s ~= 1 or cap ~= "" then
|
||||
table.insert(Table,cap)
|
||||
end
|
||||
last_end = e+1
|
||||
s, e, cap = pString:find(fpat, last_end)
|
||||
end
|
||||
if last_end <= #pString then
|
||||
cap = pString:sub(last_end)
|
||||
table.insert(Table, cap)
|
||||
end
|
||||
return Table
|
||||
end
|
||||
|
||||
return String
|
Loading…
Reference in a new issue