test Import Profile

This commit is contained in:
Crum
2018-06-21 16:27:38 -05:00
parent f0d22378c5
commit a303fca56b
+15 -20
View File
@@ -14,20 +14,15 @@ end
local error, tonumber, type = error, tonumber, type local error, tonumber, type = error, tonumber, type
local concat, insert = table.concat, table.insert local concat, insert = table.concat, table.insert
local byte, char, format, gsub, mod, sub = string.byte, string.char, string.format, string.gsub, string.fmod, string.sub local fmod = math.fmod
local byte, char, format, gsub, len, sub = string.byte, string.char, string.format, string.gsub, string.len, string.sub
local _chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' local _chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
local charTable = {} local charTable = {}
local byteToNum = {} local byteToNum = {}
local numToChar = {} local numToChar = {}
local function convert(string) for i = 1, len(_chars) do
local t = {}
gsub(string, "%-?%d+", function(n) t[getn(t)+1] = tonumber(n) end)
return t
end
for i = 1, getn(convert(_chars)) do
numToChar[i - 1] = sub(_chars, i, i) numToChar[i - 1] = sub(_chars, i, i)
byteToNum[byte(_chars, i)] = i - 1 byteToNum[byte(_chars, i)] = i - 1
end end
@@ -65,7 +60,7 @@ function LibBase64:Encode(text, maxLineLength, lineEnding)
-- do nothing -- do nothing
elseif type(maxLineLength) ~= "number" then elseif type(maxLineLength) ~= "number" then
error(format("Bad argument #2 to `Encode'. Expected %q or %q, got %q", "number", "nil", type(maxLineLength)), 2) error(format("Bad argument #2 to `Encode'. Expected %q or %q, got %q", "number", "nil", type(maxLineLength)), 2)
elseif mod(maxLineLength, 4) ~= 0 then elseif fmod(maxLineLength, 4) ~= 0 then
error(format("Bad argument #2 to `Encode'. Expected a multiple of 4, got %s", maxLineLength), 2) error(format("Bad argument #2 to `Encode'. Expected a multiple of 4, got %s", maxLineLength), 2)
elseif maxLineLength <= 0 then elseif maxLineLength <= 0 then
error(format("Bad argument #2 to `Encode'. Expected a number > 0, got %s", maxLineLength), 2) error(format("Bad argument #2 to `Encode'. Expected a number > 0, got %s", maxLineLength), 2)
@@ -92,16 +87,16 @@ function LibBase64:Encode(text, maxLineLength, lineEnding)
end end
local num = a * 2^16 + b * 2^8 + c local num = a * 2^16 + b * 2^8 + c
local d = mod(num, 2^6) local d = fmod(num, 2^6)
num = (num - d) / 2^6 num = (num - d) / 2^6
local c = mod(num, 2^6) local c = fmod(num, 2^6)
num = (num - c) / 2^6 num = (num - c) / 2^6
local b = mod(num, 2^6) local b = fmod(num, 2^6)
num = (num - b) / 2^6 num = (num - b) / 2^6
local a = mod(num, 2^6) local a = fmod(num, 2^6)
t[getn(t)+1] = numToChar[a] t[getn(t)+1] = numToChar[a]
@@ -112,7 +107,7 @@ function LibBase64:Encode(text, maxLineLength, lineEnding)
t[getn(t)+1] = (nilNum >= 1) and "=" or numToChar[d] t[getn(t)+1] = (nilNum >= 1) and "=" or numToChar[d]
currentLength = currentLength + 4 currentLength = currentLength + 4
if maxLineLength and mod(currentLength, maxLineLength) == 0 then if maxLineLength and fmod(currentLength, maxLineLength) == 0 then
t[getn(t)+1] = lineEnding t[getn(t)+1] = lineEnding
end end
end end
@@ -137,7 +132,7 @@ function LibBase64:Decode(text)
error(format("Bad argument #1 to `Decode'. Expected %q, got %q", "string", type(text)), 2) error(format("Bad argument #1 to `Decode'. Expected %q, got %q", "string", type(text)), 2)
end end
for i = 1, getn(text) do for i = 1, len(text) do
local byte = byte(text, i) local byte = byte(text, i)
if whitespace[byte] or byte == equals_byte then if whitespace[byte] or byte == equals_byte then
-- do nothing -- do nothing
@@ -169,13 +164,13 @@ function LibBase64:Decode(text)
local num = a * 2^18 + b * 2^12 + c * 2^6 + d local num = a * 2^18 + b * 2^12 + c * 2^6 + d
local c = mod(num, 2^8) local c = fmod(num, 2^8)
num = (num - c) / 2^8 num = (num - c) / 2^8
local b = mod(num, 2^8) local b = fmod(num, 2^8)
num = (num - b) / 2^8 num = (num - b) / 2^8
local a = mod(num, 2^8) local a = fmod(num, 2^8)
t[getn(t)+1] = char(a) t[getn(t)+1] = char(a)
if nilNum < 2 then if nilNum < 2 then
@@ -204,11 +199,11 @@ function LibBase64:IsBase64(text)
error(format("Bad argument #1 to `IsBase64'. Expected %q, got %q", "string", type(text)), 2) error(format("Bad argument #1 to `IsBase64'. Expected %q, got %q", "string", type(text)), 2)
end end
if mod(getn(text), 4) ~= 0 then if fmod(len(text), 4) ~= 0 then
return false return false
end end
for i = 1, getn(text) do for i = 1, len(text) do
local byte = byte(text, i) local byte = byte(text, i)
if whitespace[byte] or byte == equals_byte then if whitespace[byte] or byte == equals_byte then
-- do nothing -- do nothing