mirror of
https://github.com/brues-code/pfUI.git
synced 2026-11-06 10:38:58 +00:00
Use ClassicAPI.strsplit for pfUI's strsplit
This commit is contained in:
+5
-27
@@ -92,33 +92,11 @@ gfind = string.gmatch or string.gfind
|
|||||||
mod = math.mod or mod
|
mod = math.mod or mod
|
||||||
|
|
||||||
-- [ strsplit ]
|
-- [ strsplit ]
|
||||||
-- Splits a string using a delimiter. Self-contained on purpose: it does NOT
|
-- ClassicAPI's strsplit, taken from the ClassicAPI table, which no addon can
|
||||||
-- delegate to the global strsplit / string.split, because third-party addons
|
-- overwrite. Third-party addons replace the global strsplit / string.split
|
||||||
-- clobber those (e.g. BigWigs' SpellRequests redefines string:split to return
|
-- (e.g. BigWigs' SpellRequests makes string:split return a table), and bare
|
||||||
-- a table, which would make this return a single table instead of r,g,b,a and
|
-- strsplit calls inside the pfUI environment resolve to this copy.
|
||||||
-- break color/version parsing depending on load order). Delimiter chars are
|
pfUI.api.strsplit = ClassicAPI.strsplit
|
||||||
-- treated as a set (any one char splits), and empty fields are preserved
|
|
||||||
-- ("a,,b" -> "a", "", "b"), matching real strsplit semantics.
|
|
||||||
-- 'delimiter' [string] characters that will be interpreted as delimiter
|
|
||||||
-- characters (bytes) in the string.
|
|
||||||
-- 'subject' [string] String to split.
|
|
||||||
-- return: [list] a list of strings.
|
|
||||||
local sfind, ssub, sgsub = string.find, string.sub, string.gsub
|
|
||||||
function pfUI.api.strsplit(delimiter, subject)
|
|
||||||
if not subject then return nil 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
|
|
||||||
|
|
||||||
-- [ isempty ]
|
-- [ isempty ]
|
||||||
-- Returns true if a table is empty or not existing, otherwise false.
|
-- Returns true if a table is empty or not existing, otherwise false.
|
||||||
|
|||||||
@@ -1303,7 +1303,7 @@ pfUI:RegisterModule("equipmentmanager", function()
|
|||||||
local function InForm(value)
|
local function InForm(value)
|
||||||
local formID = GetShapeshiftFormID() or 0
|
local formID = GetShapeshiftFormID() or 0
|
||||||
if value == "any" then return formID ~= 0 end
|
if value == "any" then return formID ~= 0 end
|
||||||
for _, id in ipairs({ strsplit(",", value) }) do
|
for _, id in ipairs({ strsplit(",", value or "") }) do
|
||||||
if tonumber(id) == formID then return true end
|
if tonumber(id) == formID then return true end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -368,7 +368,7 @@ pfUI:SetScript("OnEvent", function()
|
|||||||
pfUI.version.major, pfUI.version.minor, pfUI.version.fix = 0, 0, 0
|
pfUI.version.major, pfUI.version.minor, pfUI.version.fix = 0, 0, 0
|
||||||
pfUI.version.string = "dev"
|
pfUI.version.string = "dev"
|
||||||
else
|
else
|
||||||
local major, minor, fix = pfUI.api.strsplit(".", string.gsub(raw, "^[vV]", ""))
|
local major, minor, fix = pfUI.api.strsplit(".", (string.gsub(raw, "^[vV]", "")))
|
||||||
pfUI.version.major = tonumber(major) or 0
|
pfUI.version.major = tonumber(major) or 0
|
||||||
pfUI.version.minor = tonumber(minor) or 0
|
pfUI.version.minor = tonumber(minor) or 0
|
||||||
pfUI.version.fix = tonumber(fix) or 0
|
pfUI.version.fix = tonumber(fix) or 0
|
||||||
|
|||||||
Reference in New Issue
Block a user