From 89d116200f83518f5da6cc11dda0236c126ae9cb Mon Sep 17 00:00:00 2001 From: Matt Calsada Date: Tue, 14 Jul 2020 17:58:27 -0400 Subject: [PATCH] Initial commit --- AtlasHelpers.lua | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ Config.xml | 9 ++++++ 2 files changed, 84 insertions(+) create mode 100644 AtlasHelpers.lua create mode 100644 Config.xml diff --git a/AtlasHelpers.lua b/AtlasHelpers.lua new file mode 100644 index 0000000..b9ba614 --- /dev/null +++ b/AtlasHelpers.lua @@ -0,0 +1,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 \ No newline at end of file diff --git a/Config.xml b/Config.xml new file mode 100644 index 0000000..34ecd59 --- /dev/null +++ b/Config.xml @@ -0,0 +1,9 @@ + + Atlas Library + Atlas Systems, Inc. + 1.1 + false + Library + + Contains helper methods for use with user addons. +