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 = {}