util/xmllex.lua

changeset 3995
7214dc7a5642
parent 3992
de77ec2b49bc
child 4002
2b53b4b5d46e
--- a/util/xmllex.lua	Mon Jan 03 22:20:49 2011 +0000
+++ b/util/xmllex.lua	Tue Jan 04 00:23:51 2011 +0000
@@ -29,6 +29,7 @@
 
 local function handleoutside ( str , r , initial )
 	local a , b , close = str:find ( "<(/?)" , initial )
+
 	if not a then
 		r.state = "outside"
 		return false
@@ -88,6 +89,8 @@
 local function index ( str , r )
 	r = r or { depth = 0, state = "outside" }
 	
+	local initial = 1
+	
 	if not r[#r] then
 		r[1] = setmetatable ( {
 			msgs = { str } ;
@@ -98,17 +101,18 @@
 		tblinsert ( r[#r].msgs , str )
 	end
 	
-	repeat
+	while true do
 		if r.state == "outside" then
-			if not handleoutside ( str , r , r[#r].start ) then
+			if not handleoutside ( str , r , initial ) then
 				break
 			end
 		else
-			if not handleinside ( str , r , r[#r].start ) then
+			if not handleinside ( str , r , initial ) then
 				break
 			end
 		end
-	until false
+		initial = r[#r].start
+	end
 
 	return r
 end
@@ -148,10 +152,17 @@
 end
 
 local function tagindex_to_tree(indices)
+	if not start then
+		start = 1
+		finish = #indices
+	end
+	
 	local root = { tags = { } }
 	local leaf = root
 	
-	for k ,v in ipairs ( indices ) do
+	for i = start , finish do
+		local v = indices [ i ]
+		
 		if v.type == "selfclosing" then
 			local newleaf = new_stanza ( )
 			newleaf.opentag = v
@@ -182,6 +193,7 @@
 end
 
 return {
-	index = index;
-	tagindex_to_tree = tagindex_to_tree;
+	index = index ;
+	tagindex_to_tree = tagindex_to_tree ;
+	process_starttag = process_starttag ;
 };

mercurial