-
Notifications
You must be signed in to change notification settings - Fork 0
/
AtlasHelpers.lua
75 lines (54 loc) · 1.59 KB
/
AtlasHelpers.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
local Class = {};
AtlasHelpers = Class;
function Class.StringSplit(delimiter, text)
local list = {};
local pos = 1;
if string.find("", delimiter, 1) then -- this would result in endless loops
error("Delimiter cannot be an empty string.");
end
while 1 do
local first,last = string.find(text, delimiter, pos);
if first then -- found?
table.insert(list, string.sub(text, pos, first-1));
pos = last+1;
else
table.insert(list, string.sub(text, pos));
break;
end
end
return list;
end
function Class.UrlDecode(str)
str = string.gsub (str, "+", " ");
str = string.gsub (str, "%%(%x%x)",
function(h) return string.char(tonumber(h,16)) end);
str = string.gsub (str, "\r\n", "\n");
return str;
end
function Class.UrlEncode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n");
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end);
str = string.gsub (str, " ", "+");
end
return str;
end
function Class. Trim(s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"));
end
function Class.GetElementsByClassName(className, rootElements)
local classElements = {};
if (rootElements ~= nil and className ~= nil and className ~= "") then
local upperCaseLabel = className:upper();
for j =0, rootElements.Count - 1 do
local spanRow = rootElements:get_Item(j);
local spanClass = spanRow:GetAttribute("className");
if string.match(spanClass:upper(), upperCaseLabel) == upperCaseLabel then
table.insert(classElements, spanRow);
end
end
end
return classElements;
end
return AtlasHelpers