diff options
author | Mike Mason <ms13sp@gmail.com> | 2007-11-28 15:26:13 +0000 |
---|---|---|
committer | Mike Mason <ms13sp@gmail.com> | 2007-11-28 15:26:13 +0000 |
commit | dbddbd9b0cec1bfe8e92a39552b28ab2f11195d9 (patch) | |
tree | 94bf4751bfb9f58f6854244d98d9cfac1852fc03 /lib/fs.lua | |
parent | 7538b26d89faab270cd90ea72415d4dd2c988708 (diff) | |
download | acf-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.lua | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -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 + |