From f5c08822f8c5c94b6c7caef2aac6b7e0bacd1949 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 31 Oct 2026 02:49:46 -0500 Subject: [PATCH] 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. --- api/api.lua | 17 ++++++++++++----- api/unitframes.lua | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/api/api.lua b/api/api.lua index cbf240e3..21457f82 100644 --- a/api/api.lua +++ b/api/api.lua @@ -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 diff --git a/api/unitframes.lua b/api/unitframes.lua index 1921cfbc..0ea49aef 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -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 = {}