scansion/stanzacmp.lua

changeset 92
9a58c8ee0757
parent 91
73fe018a0c5a
child 99
dc56d434e406
equal deleted inserted replaced
91:73fe018a0c5a 92:9a58c8ee0757
69 if stanza2.attr[k] ~= v then 69 if stanza2.attr[k] ~= v then
70 return false; 70 return false;
71 end 71 end
72 end 72 end
73 73
74 local stanza2_pos = 1; 74 local matched_children = {};
75 for _, child in ipairs(stanza1) do 75 for _, child in ipairs(stanza1) do
76 if type(child) == "table" or child:match("%S") then 76 if type(child) == "table" or child:match("%S") then
77 local match; 77 local match;
78 -- Iterate through remaining nodes in stanza2, looking for a match 78 -- Iterate through remaining nodes in stanza2, looking for a match
79 local stanza2_pos = 1;
79 while stanza2_pos <= #stanza2 do 80 while stanza2_pos <= #stanza2 do
80 local child2 = stanza2[stanza2_pos]; 81 if not matched_children[stanza2_pos] then
81 stanza2_pos = stanza2_pos + 1; 82 local child2 = stanza2[stanza2_pos];
83 stanza2_pos = stanza2_pos + 1;
82 84
83 if type(child2) == type(child) then 85 if type(child2) == type(child) then
84 if type(child) == "table" and child2.name == child.name and child2.attr.xmlns == child.attr.xmlns then 86 if type(child) == "table" and child2.name == child.name and child2.attr.xmlns == child.attr.xmlns then
85 -- Strict deep match 87 -- Strict deep match
86 match = stanzas_match(child, child2); 88 match = stanzas_strict_match(child, child2);
87 elseif type(child) == "string" then -- Text nodes, must be equal, ignoring leading/trailing whitespace 89 elseif type(child) == "string" then -- Text nodes, must be equal, ignoring leading/trailing whitespace
88 match = trim(child) == trim(child2); 90 match = trim(child) == trim(child2);
91 end
92 if match then
93 break;
94 end
89 end 95 end
90 break;
91 end 96 end
92 end 97 end
93 if not match then 98 if not match then
99 --print(_, "No match for ", child:pretty_print())
94 return false; 100 return false;
95 end 101 end
96 end 102 end
97 end 103 end
98 return true; 104 return true;

mercurial