forked from DennisWG/Roid-Macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtility.lua
61 lines (52 loc) · 1.6 KB
/
Utility.lua
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
--[[
Author: Dennis Werner Garske (DWG)
License: MIT License
]]
local _G = _G or getfenv(0)
local Roids = _G.Roids or {} -- redundant since we're loading first but peace of mind if another file is added top of chain
-- Splits the given string into a list of sub-strings
-- str: The string to split
-- seperatorPattern: The seperator between sub-string. May contain patterns
-- returns: A list of sub-strings
function Roids.splitString(str, seperatorPattern)
local tbl = {};
if not str then
return tbl;
end
local pattern = "(.-)" .. seperatorPattern;
local lastEnd = 1;
local s, e, cap = string.find(str, pattern, 1);
while s do
if s ~= 1 or cap ~= "" then
table.insert(tbl,cap);
end
lastEnd = e + 1;
s, e, cap = string.find(str, pattern, lastEnd);
end
if lastEnd <= string.len(str) then
cap = string.sub(str, lastEnd);
table.insert(tbl, cap);
end
return tbl
end
-- Prints all the given arguments into WoW's default chat frame
function Roids.Print(...)
if not DEFAULT_CHAT_FRAME:IsVisible() then
FCF_SelectDockFrame(DEFAULT_CHAT_FRAME)
end
local out = "|cffc8c864Roids:|r";
for i=1, arg.n, 1 do
out = out..tostring(arg[i]).." ";
end
DEFAULT_CHAT_FRAME:AddMessage(out)
end
-- Trims any leading or trailing white space characters from the given string
-- str: The string to trim
-- returns: The trimmed string
function Roids.Trim(str)
if not str then
return nil;
end
return string.gsub(str,"^%s*(.-)%s*$", "%1");
end
_G["Roids"] = Roids