-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsafe.lua
More file actions
35 lines (29 loc) · 867 Bytes
/
safe.lua
File metadata and controls
35 lines (29 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local safe = {
_VERSION = 1.1,
_URL = 'https://github.com/Bilwin/gmod-scripts/blob/main/safe.lua',
_LICENSE = 'https://github.com/Bilwin/gmod-scripts/blob/main/LICENSE'
}
function safe:html(str)
return str:gsub('&', '&'):gsub('<', '<'):gsub('>', '>')
end
function safe:steam_id(str)
return str:gsub('[^%w:_]', '') or ''
end
function safe:explode_quotes(str)
str = ' ' .. str .. ' '
local res = {}
local ind = 1
while true do
local sInd, start = str:find('[^%s]', ind)
if not sInd then break end
ind = sInd + 1
local quoted = str:sub(sInd, sInd):match('["\']') and true or false
local fInd, finish = str:find(quoted and '["\']' || '[%s]', ind)
if not fInd then break end
ind = fInd + 1
local str = str:sub(quoted and sInd + 1 or sInd, fInd - 1)
res[#res + 1] = str
end
return res
end
return safe