mirror of
https://github.com/TangentFoxy/love-release.git
synced 2025-07-28 02:52:20 +00:00
utils.lua.escape_string_regex rewritten with single string.gsub call.
This commit is contained in:
committed by
Antonin Décimo
parent
8dbfb3ceca
commit
cad47b8535
@@ -128,11 +128,13 @@ end
|
|||||||
--- Escapes a string to use as a regex.
|
--- Escapes a string to use as a regex.
|
||||||
-- @string string to escape.
|
-- @string string to escape.
|
||||||
function utils.lua.escape_string_regex(string)
|
function utils.lua.escape_string_regex(string)
|
||||||
-- ^$()%.[]*+-?
|
return string:gsub('[%^%$%(%)%%%.%[%]%*%+%-%?%z]', {
|
||||||
return string:gsub('%%', '%%%%'):gsub('^%^', '%%^'):gsub('%$$', '%%$')
|
['^'] = '%^'; ['$'] = '%$'; ['('] = '%(';
|
||||||
:gsub('%(', '%%('):gsub('%)', '%%)'):gsub('%.', '%%.')
|
[')'] = '%)'; ['%'] = '%%'; ['.'] = '%.';
|
||||||
:gsub('%[', '%%['):gsub('%]', '%%]'):gsub('%*', '%%*')
|
['['] = '%['; [']'] = '%]'; ['*'] = '%*';
|
||||||
:gsub('%+', '%%+'):gsub('%-', '%%-'):gsub('%?', '%%?')
|
['+'] = '%+'; ['-'] = '%-'; ['?'] = '%?';
|
||||||
|
['\0'] = '%z';
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user