-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.lua
More file actions
81 lines (69 loc) · 2.06 KB
/
Copy pathUtil.lua
File metadata and controls
81 lines (69 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
local _, VoxGM = ...
local Util = VoxGM.Util
function Util:Print(msg)
print("|cff00ccff[VoxGM]|r " .. tostring(msg))
end
function Util:PrintError(msg)
print("|cffff3333[VoxGM]|r " .. tostring(msg))
end
function Util:ParseNumber(str)
if not str or str == "" then return nil end
return tonumber(strtrim(str))
end
function Util:ParseID(str)
local n = self:ParseNumber(str)
if not n then return nil end
if n ~= math.floor(n) or n < 1 then return nil end
return math.floor(n)
end
function Util:Clamp(val, minVal, maxVal)
if val < minVal then return minVal end
if val > maxVal then return maxVal end
return val
end
function Util:Trim(str)
return strtrim(str or "")
end
function Util:DeepCopy(tbl)
if type(tbl) ~= "table" then return tbl end
local copy = {}
for k, v in pairs(tbl) do
copy[k] = self:DeepCopy(v)
end
return copy
end
function Util:StatusMessage(frame, msg, color)
if frame and frame.statusText then
color = color or VoxGM.C.COLOR_WHITE
frame.statusText:SetTextColor(color.r, color.g, color.b)
frame.statusText:SetText(msg)
-- Auto-clear after 5 seconds
if frame.statusTimer then frame.statusTimer:Cancel() end
frame.statusTimer = C_Timer.NewTimer(5, function()
if frame.statusText then
frame.statusText:SetText("Ready")
frame.statusText:SetTextColor(1, 1, 1)
end
end)
end
end
function Util:ValidateNumericInput(editBox, min, max, label)
local val = self:ParseNumber(editBox:GetText())
if not val then
self:PrintError((label or "Value") .. " must be a number.")
return nil
end
if min and max then
val = self:Clamp(val, min, max)
end
return val
end
-- Strip characters that could cause problems in dot-commands.
-- Removes control characters (0x00-0x1F except space), pipes, and
-- leading/trailing whitespace.
function Util:SanitizeText(str)
if not str then return "" end
str = strtrim(str)
str = str:gsub("[%c|;]", "")
return str
end