--beware this function allows "holes" in the table
--function tableLength(atable)
	--return #atable
--end
--replaced with the function from psp.lua to get the same behaviour
function tableLength(atable)
	local maxn=1
	if atable==nil then
		return 0
	end
	while true do
		if atable[maxn]==nil then
			return maxn-1
		else
			maxn=maxn+1
		end
	end 	
end

function getMemoryInfo()
	return 	math.floor(collectgarbage("count")).." kb used"
end

function matchString(astring, apattern)
	return string.match(astring, apattern)
end

--function insertIntoTable(atable, anelement)
--	return table.insert(atable, anelement)
--end

function GC()
	collectgarbage("collect")
end

--function getTextSize(afont, amessage)
--	return afont:getTextSize(message)
--end

function stringSize(astring)
	return string.len(astring)
end

function getFolderList(dir)
	local lfiles = System.listDirectory(dir)
	local directories = {}
	local lfi=1
	local di=1
	
	for lfi=1,tableLength(lfiles) do
		if matchString(lfiles[lfi].name, "%.")==nil then --it is a directory
			directories[di]=lfiles[lfi].name
			di=di+1
		end
	end
	return directories
end

function getFileList(dir)
	local lfiles = System.listDirectory(dir)
	local allfiles = {}
	local lfi=1
	local fi=1
	
	for lfi=1,tableLength(lfiles) do
		fdebug(lfiles[lfi].name)
		fdebug(matchString(lfiles[lfi].name, "%."))
		if matchString(lfiles[lfi].name, "%.")=="." then --it is a file
			allfiles[fi]=lfiles[lfi].name
			fi=fi+1
		end
	end
	return allfiles
end


function getSnapshotFolder()
	return "snapshots"
end