summaryrefslogtreecommitdiffstats
path: root/lib/format.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-12-27 20:54:24 +0000
committerTed Trask <ttrask01@yahoo.com>2008-12-27 20:54:24 +0000
commitbca82aa8e45aa89eb4c7607f1669564fcf823448 (patch)
treef0662ff05597b171e234b9f369296d323d57dc4d /lib/format.lua
parentd2b00cb50188545f79fb518e1a53378bdd23c8f9 (diff)
downloadacf-core-bca82aa8e45aa89eb4c7607f1669564fcf823448.tar.bz2
acf-core-bca82aa8e45aa89eb4c7607f1669564fcf823448.tar.xz
Modified format string_to_table so didn't crash when passed nil.release-0.4.17
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1653 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'lib/format.lua')
-rw-r--r--lib/format.lua34
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/format.lua b/lib/format.lua
index 0044787..6ef831a 100644
--- a/lib/format.lua
+++ b/lib/format.lua
@@ -157,22 +157,24 @@ end
-- example: format.string_to_table( "Anna, Bob, Charlie,Dolores", ",%s*")
function string_to_table ( text, delimiter)
local list = {}
- -- this would result in endless loops
- if string.find("", delimiter) then
- -- delimiter matches empty string!
- for i=1,#text do
- list[#list + 1] = string.sub(text, i, i)
- end
- else
- local pos = 1
- 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
+ if text then
+ -- this would result in endless loops
+ if string.find("", delimiter) then
+ -- delimiter matches empty string!
+ for i=1,#text do
+ list[#list + 1] = string.sub(text, i, i)
+ end
+ else
+ local pos = 1
+ 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
end
end