summaryrefslogtreecommitdiffstats
path: root/lib/fs.lua
diff options
context:
space:
mode:
authorMike Mason <ms13sp@gmail.com>2007-11-28 15:26:13 +0000
committerMike Mason <ms13sp@gmail.com>2007-11-28 15:26:13 +0000
commitdbddbd9b0cec1bfe8e92a39552b28ab2f11195d9 (patch)
tree94bf4751bfb9f58f6854244d98d9cfac1852fc03 /lib/fs.lua
parent7538b26d89faab270cd90ea72415d4dd2c988708 (diff)
downloadacf-core-dbddbd9b0cec1bfe8e92a39552b28ab2f11195d9.tar.bz2
acf-core-dbddbd9b0cec1bfe8e92a39552b28ab2f11195d9.tar.xz
added split and join to fs.lua and gave them function names so we don't have to strsplit = require split. Added a date string to table function in date.lua
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@378 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib/fs.lua')
-rw-r--r--lib/fs.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/fs.lua b/lib/fs.lua
index 88df9f1..79d0cdc 100644
--- a/lib/fs.lua
+++ b/lib/fs.lua
@@ -155,3 +155,39 @@ function find ( what, where )
end
end
+-- This code comes from http://lua-users.org/wiki/SplitJoin
+-- -- example: strjoin(", ", {"Anna", "Bob", "Charlie", "Dolores"})
+function table_to_string (delimiter, list)
+ local len = getn(list)
+ if len == 0 then
+ return ""
+ end
+ local string = list[1]
+ for i = 2, len do
+ string = string .. delimiter .. list[i]
+ end
+ return string
+end
+
+-- This code comes from http://lua-users.org/wiki/SplitJoin
+-- example: strsplit(",%s*", "Anna, Bob, Charlie,Dolores")
+function string_to_table (delimiter, text)
+ local list = {}
+ local pos = 1
+ -- this would result in endless loops
+ if string.find("", delimiter, 1) then
+ error("delimiter matches 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
+