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:
Brues
2026-10-31 02:49:46 -05:00
parent 6f5c225ec3
commit f5c08822f8
2 changed files with 14 additions and 7 deletions
+12 -5
View File
@@ -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
View File
@@ -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 = {}