mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-27 18:06:02 +00:00
api: let sanitize pattern prioritize numbers
This commit is contained in:
+22
-14
@@ -143,17 +143,27 @@ end
|
||||
-- 'pattern' [string] unformatted pattern
|
||||
-- returns: [string] simplified gfind compatible pattern
|
||||
local sanitize_cache = {}
|
||||
function pfUI.api.SanitizePattern(pattern)
|
||||
function pfUI.api.SanitizePattern(pattern, dbg)
|
||||
if not sanitize_cache[pattern] then
|
||||
local ret = pattern
|
||||
-- escape brackets
|
||||
ret = gsub(ret, "%((.+)%)", "%%(%1%%)")
|
||||
-- remove capture indexes
|
||||
ret = gsub(ret, "%d%$","")
|
||||
|
||||
-- catch all characters
|
||||
ret = gsub(ret, "%%%a","(.+)")
|
||||
ret = gsub(ret, "(%%%a)","%(%1+%)")
|
||||
|
||||
-- convert all %s to .+
|
||||
ret = gsub(ret, "%%s%+",".+")
|
||||
|
||||
-- set priority to numbers over strings
|
||||
ret = gsub(ret, "%(.%+%)%(%%d%+%)","%(.-%)%(%%d%+%)")
|
||||
|
||||
-- cache it
|
||||
sanitize_cache[pattern] = ret
|
||||
end
|
||||
|
||||
return sanitize_cache[pattern]
|
||||
end
|
||||
|
||||
@@ -165,19 +175,17 @@ end
|
||||
function pfUI.api.cmatch(str, pat)
|
||||
-- read capture indexes
|
||||
local a,b,c,d,e = GetCaptures(pat)
|
||||
local _, _, va, vb, vc, vd, ve = string.find(str, pfUI.api.SanitizePattern(pat))
|
||||
|
||||
for va, vb, vc, vd, ve in string.gfind(str, pfUI.api.SanitizePattern(pat)) do
|
||||
-- initialize return values
|
||||
local ra, rb, rc, rd, re
|
||||
-- put entries into the proper return values
|
||||
local ra, rb, rc, rd, re
|
||||
ra = e == "1" and ve or d == "1" and vd or c == "1" and vc or b == "1" and vb or va
|
||||
rb = e == "2" and ve or d == "2" and vd or c == "2" and vc or a == "2" and va or vb
|
||||
rc = e == "3" and ve or d == "3" and vd or a == "3" and va or b == "3" and vb or vc
|
||||
rd = e == "4" and ve or a == "4" and va or c == "4" and vc or b == "4" and vb or vd
|
||||
re = a == "5" and va or d == "5" and vd or c == "5" and vc or b == "5" and vb or ve
|
||||
|
||||
-- put entries into the proper return values
|
||||
ra = e == "1" and ve or d == "1" and vd or c == "1" and vc or b == "1" and vb or va
|
||||
rb = e == "2" and ve or d == "2" and vd or c == "2" and vc or a == "2" and va or vb
|
||||
rc = e == "3" and ve or d == "3" and vd or a == "3" and va or b == "3" and vb or vc
|
||||
rd = e == "4" and ve or a == "4" and va or c == "4" and vc or b == "4" and vb or vd
|
||||
re = a == "5" and va or d == "5" and vd or c == "5" and vc or b == "5" and vb or ve
|
||||
return ra, rb, rc, rd, re
|
||||
end
|
||||
return ra, rb, rc, rd, re
|
||||
end
|
||||
|
||||
-- [ GetItemLinkByName ]
|
||||
@@ -903,4 +911,4 @@ function pfUI.api.GetColorGradient(perc)
|
||||
gradientcolors[perc].g,
|
||||
gradientcolors[perc].b,
|
||||
gradientcolors[perc].h
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user