diff options
author | Natanael Copa <natanael.copa@gmail.com> | 2007-07-27 12:53:38 +0000 |
---|---|---|
committer | Natanael Copa <natanael.copa@gmail.com> | 2007-07-27 12:53:38 +0000 |
commit | dc53423183a0c459284ebd139022b707f01af006 (patch) | |
tree | 8a67a2904ec991028bddd429d57eec114b05baab /lib/split.lua | |
parent | 275c80281ba2e84b8d810bdb1c2b7f8c9a4333d9 (diff) | |
download | acf-core-050e043248df3a254daaddae7eb9d0c9f4cf1c9f.tar.bz2 acf-core-050e043248df3a254daaddae7eb9d0c9f4cf1c9f.tar.xz |
moved core files to new dir structurev2.0_alpha1
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@219 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib/split.lua')
-rw-r--r-- | lib/split.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/split.lua b/lib/split.lua new file mode 100644 index 0000000..f3e2e95 --- /dev/null +++ b/lib/split.lua @@ -0,0 +1,31 @@ +--[[ + module for splitting a string to an array +]]-- + +module (..., package.seeall) + +-- This code comes from http://lua-users.org/wiki/SplitJoin + +-- Split text into a list consisting of the strings in text, +-- separated by strings matching delimiter (which may be a pattern). +-- example: strsplit(",%s*", "Anna, Bob, Charlie,Dolores") +return function (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 + |