2024-02-12 22:05:36 -08:00
|
|
|
local string_util = {}
|
|
|
|
|
|
|
|
function string_util.trim(str)
|
|
|
|
return str:gsub("%s+", "")
|
|
|
|
end
|
|
|
|
|
|
|
|
function string_util.escape(str)
|
|
|
|
return str:gsub("[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%1")
|
|
|
|
end
|
|
|
|
|
|
|
|
function string_util.ends_with(str, suffix)
|
|
|
|
return str:sub(-#suffix) == suffix
|
|
|
|
end
|
|
|
|
|
2024-03-16 10:07:12 -07:00
|
|
|
function string_util.is_str_empty(target)
|
|
|
|
return target == nil or target == ""
|
|
|
|
end
|
|
|
|
|
2024-04-05 08:23:17 -07:00
|
|
|
function string_util.convert_empty_to_nil(target)
|
|
|
|
if target == "" then
|
|
|
|
return nil
|
|
|
|
else
|
|
|
|
return target
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-04-27 04:07:41 -07:00
|
|
|
function string_util.split(str, delimiter)
|
|
|
|
local result = {}
|
|
|
|
|
|
|
|
for token in string.gmatch(str, "[^" .. delimiter .. "]+") do
|
|
|
|
table.insert(result, token)
|
|
|
|
end
|
|
|
|
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2024-02-12 22:05:36 -08:00
|
|
|
return string_util
|