--[[
 *******************************************************************************
 * Utility functions
 *******************************************************************************
--]]

function sizeString(aSize)
  local Size = 1 * aSize;
  local Suffixes = { "B", "kB", "MB", "GB", "TB", "PB" };
  local Index = 1;
  while ((Size > 1000) and (Index < 6)) do
    Index = Index + 1;
    Size = Size / 1000;
  end
  local n1, n2 = math.modf(Size * 10);
  return (n1 / 10) .. " " .. Suffixes[Index];
end

function trim (s)
	return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end



--[[
 *******************************************************************************
 * Storage device functions
 *******************************************************************************
--]]


function physicalStorageDeviceLine1()
  local Result = "";
  if (Vars.HardwareVendor ~= nil) then
    Result = Result .. Vars.HardwareVendor .. " ";
  end
  if (Vars.HardwareModel ~= nil) then
    Result = Result .. Vars.HardwareModel .. " ";
  end
--[[  if (Vars.HardwareSerial ~= "") then
    Result = Result .. Vars.HardwareSerial .. " ";
  end
]]--
  return trim(Result)
end

function valueIfExists(Val, Def) 
  if (Val ~= nil) then
    return Val;
  else
    return "";
  end
end
