diff options
author | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-08-05 21:50:41 +0200 |
---|---|---|
committer | Adrian C. (anrxc) <anrxc@sysphere.org> | 2009-08-05 21:50:41 +0200 |
commit | 4c74de711f564d26ebefef7f9422289bd76ef8c2 (patch) | |
tree | 404eb00b19214c8455dc1d0397d34353b895efce /helpers.lua | |
parent | 2d4efa6893a582a7bc6a15b4840a116c0547b534 (diff) | |
download | vicious-legacy-4c74de711f564d26ebefef7f9422289bd76ef8c2.tar.xz |
Padding removed, along with deprecated helper functions.
If you have any use for it then continue using an older vicious tag,
or keep maintaining it in your local vicious copy.
Diffstat (limited to 'helpers.lua')
-rw-r--r-- | helpers.lua | 76 |
1 files changed, 1 insertions, 75 deletions
diff --git a/helpers.lua b/helpers.lua index 67319ed..874de73 100644 --- a/helpers.lua +++ b/helpers.lua @@ -5,18 +5,7 @@ -- {{{ Grab environment local pairs = pairs -local tonumber = tonumber -local tostring = tostring -local table = { insert = table.insert } -local math = { - pow = math.pow, - floor = math.floor -} -local string = { - sub = string.sub, - gsub = string.gsub, - find = string.find -} +local string = { gsub = string.gsub } -- }}} @@ -27,78 +16,15 @@ module("vicious.helpers") -- {{{ Helper functions -- {{{ Format a string with args function format(format, args) - -- Todo: Find a more efficient way to do this - -- Format a string for var, val in pairs(args) do format = string.gsub(format, "$" .. var, val) end - -- Return formatted string return format end -- }}} --- {{{ Padd a number to a minimum amount of digits -function padd(number, padding) - s = tostring(number) - - if padding == nil then - return s - end - - for i=1, padding do - if math.floor(number/math.pow(10,(i-1))) == 0 then - s = "0" .. s - end - end - - if number == 0 then - s = s:sub(2) - end - - return s -end --- }}} - --- {{{ Convert amount of bytes to string -function bytes_to_string(bytes, sec, padding) - if bytes == nil or tonumber(bytes) == nil then - return "" - end - - bytes = tonumber(bytes) - - local signs = {} - signs[1] = " b" - signs[2] = "KiB" - signs[3] = "MiB" - signs[4] = "GiB" - signs[5] = "TiB" - - sign = 1 - - while bytes/1024 > 1 and signs[sign+1] ~= nil do - bytes = bytes/1024 - sign = sign+1 - end - - bytes = bytes*10 - bytes = math.floor(bytes)/10 - - if padding then - bytes = padd(bytes*10, padding+1) - bytes = bytes:sub(1, bytes:len()-1) .. "." .. bytes:sub(bytes:len()) - end - - if sec then - return tostring(bytes) .. signs[sign] .. "ps" - else - return tostring(bytes) .. signs[sign] - end -end --- }}} - --{{{ Escape a string function escape(text) local xml_entities = { |