mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-31 07:56:57 +00:00
Keep empty fields and literal delimiters in strsplit
pfUI.api.strsplit (also the bare strsplit in module code) built a
"([^%s]+)" pattern from the delimiter. That dropped empty fields
("a,,b" gave "a", "b") despite the comment, and a delimiter that is a
pattern character (% ] ^ -) broke the pattern. It now scans for an
escaped character class and keeps every field, like WoW's strsplit.
The custom buff indicator list skips the empty entries this now yields
for "" and the list editor's leading "#", so an empty list no longer
scans auras.
This commit is contained in:
+12
-5
@@ -103,13 +103,20 @@ mod = math.mod or mod
|
||||
-- characters (bytes) in the string.
|
||||
-- 'subject' [string] String to split.
|
||||
-- return: [list] a list of strings.
|
||||
local format, sgsub = string.format, string.gsub
|
||||
local sfind, ssub, sgsub = string.find, string.sub, string.gsub
|
||||
function pfUI.api.strsplit(delimiter, subject)
|
||||
if not subject then return nil end
|
||||
local fields = {}
|
||||
delimiter = delimiter or ":"
|
||||
local pattern = format("([^%s]+)", delimiter)
|
||||
sgsub(subject, pattern, function(c) fields[table.getn(fields)+1] = c end)
|
||||
-- a character class of the delimiter bytes, each escaped so % ] ^ - stay
|
||||
-- literal
|
||||
local set = "[" .. sgsub(delimiter or ":", "(%W)", "%%%1") .. "]"
|
||||
local fields, start = {}, 1
|
||||
local pos = sfind(subject, set)
|
||||
while pos do
|
||||
table.insert(fields, ssub(subject, start, pos - 1))
|
||||
start = pos + 1
|
||||
pos = sfind(subject, set, start)
|
||||
end
|
||||
table.insert(fields, ssub(subject, start))
|
||||
return unpack(fields)
|
||||
end
|
||||
|
||||
|
||||
+2
-2
@@ -1984,8 +1984,8 @@ function pfUI.uf:RefreshUnit(unit, component)
|
||||
|
||||
if not unit.indicator_custom and unit.config.buff_indicator == "1" then
|
||||
unit.indicator_custom = {}
|
||||
for k, v in pairs({strsplit("#", unit.config.custom_indicator)}) do
|
||||
unit.indicator_custom[k] = v:lower()
|
||||
for _, v in pairs({strsplit("#", unit.config.custom_indicator)}) do
|
||||
if v ~= "" then table.insert(unit.indicator_custom, v:lower()) end
|
||||
end
|
||||
elseif not unit.indicator_custom then
|
||||
unit.indicator_custom = {}
|
||||
|
||||
Reference in New Issue
Block a user