api: unify pattern conversion for gfind

This commit is contained in:
shagu
2017-09-26 22:57:13 +02:00
parent 2d624f921c
commit a895669051
3 changed files with 47 additions and 28 deletions
+20
View File
@@ -85,6 +85,26 @@ function pfUI.api.round(input, places)
end
end
-- [ SanitizePattern ]
-- Sanitizes and convert patterns into gfind compatible ones.
-- 'pattern' [string] unformatted pattern
-- returns: [string] simplified gfind compatible pattern
function SanitizePattern(pattern)
-- escape brackets
pattern = gsub(pattern, "%(", "%%(")
pattern = gsub(pattern, "%)", "%%)")
-- remove bad capture indexes
pattern = gsub(pattern, "%d%$s","s") -- %1$s to %s
pattern = gsub(pattern, "%ds","s") -- %2s to %s
-- add capture to all findings
pattern = gsub(pattern, "%%s", "(.+)")
pattern = gsub(pattern, "%%d", "(%%d+)")
return pattern
end
-- [ GetItemLinkByName ]
-- Returns an itemLink for the given itemname
-- 'name' [string] name of the item