86 end |
87 end |
87 |
88 |
88 local function index ( str , r ) |
89 local function index ( str , r ) |
89 r = r or { depth = 0, state = "outside" } |
90 r = r or { depth = 0, state = "outside" } |
90 |
91 |
|
92 local initial = 1 |
|
93 |
91 if not r[#r] then |
94 if not r[#r] then |
92 r[1] = setmetatable ( { |
95 r[1] = setmetatable ( { |
93 msgs = { str } ; |
96 msgs = { str } ; |
94 type = "text" ; |
97 type = "text" ; |
95 start = 1 ; |
98 start = 1 ; |
96 } , m_mt ) |
99 } , m_mt ) |
97 else |
100 else |
98 tblinsert ( r[#r].msgs , str ) |
101 tblinsert ( r[#r].msgs , str ) |
99 end |
102 end |
100 |
103 |
101 repeat |
104 while true do |
102 if r.state == "outside" then |
105 if r.state == "outside" then |
103 if not handleoutside ( str , r , r[#r].start ) then |
106 if not handleoutside ( str , r , initial ) then |
104 break |
107 break |
105 end |
108 end |
106 else |
109 else |
107 if not handleinside ( str , r , r[#r].start ) then |
110 if not handleinside ( str , r , initial ) then |
108 break |
111 break |
109 end |
112 end |
110 end |
113 end |
111 until false |
114 initial = r[#r].start |
|
115 end |
112 |
116 |
113 return r |
117 return r |
114 end |
118 end |
115 |
119 |
116 local function process_starttag ( starttag ) |
120 local function process_starttag ( starttag ) |
146 local function new_stanza ( ) |
150 local function new_stanza ( ) |
147 return setmetatable ( { tags = { } } , stanza_mt ) |
151 return setmetatable ( { tags = { } } , stanza_mt ) |
148 end |
152 end |
149 |
153 |
150 local function tagindex_to_tree(indices) |
154 local function tagindex_to_tree(indices) |
|
155 if not start then |
|
156 start = 1 |
|
157 finish = #indices |
|
158 end |
|
159 |
151 local root = { tags = { } } |
160 local root = { tags = { } } |
152 local leaf = root |
161 local leaf = root |
153 |
162 |
154 for k ,v in ipairs ( indices ) do |
163 for i = start , finish do |
|
164 local v = indices [ i ] |
|
165 |
155 if v.type == "selfclosing" then |
166 if v.type == "selfclosing" then |
156 local newleaf = new_stanza ( ) |
167 local newleaf = new_stanza ( ) |
157 newleaf.opentag = v |
168 newleaf.opentag = v |
158 newleaf.selfclosing = true |
169 newleaf.selfclosing = true |
159 newleaf.parent = leaf |
170 newleaf.parent = leaf |