Commit 84ed66a
Find end tag in xml parser index
Changed files (2)
Diff
@@ -265,19 +265,30 @@ public class Tag : GLib.Object { warn ("No name for tag."); return -1; }- ++ index = entire_file.get_index (data) + start; while (true) {- previous_index = index; + while (!entire_file.substring (index).has_prefix ("</")) {+ index = entire_file.find_next_tag_token (entire_file, index);+ + if (index == -1) {+ warning (@"No end tag for $(name)");+ return -1;+ }+ }++ previous_index = index - entire_file.get_index (data); - if (!data.get_next_ascii_char (ref index, out c)) {+ if (!entire_file.get_next_ascii_char (ref index, out c)) { warn ("Unexpected end of file"); break; } if (c == '<') { slash_index = index;- data.get_next_ascii_char (ref slash_index, out slash);- if (slash == '/' && is_tag (name, slash_index)) {+ entire_file.get_next_ascii_char (ref slash_index, out slash);++ if (slash == '/' && entire_file.substring (slash_index).has_prefix (name.to_string ())) { if (start_count == 1) { return previous_index; } else {@@ -286,7 +297,7 @@ public class Tag : GLib.Object { return previous_index; } }- } else if (is_tag (name, index)) {+ } else if (entire_file.substring (index).has_prefix (name.to_string ())) { start_count++; } }@@ -22,29 +22,32 @@ public class XmlData : XmlString { public XmlData (char* data, int length) { base (data, length); start_tags = new Gee.ArrayList<int> ();- // FIXME: index index_start_tags ();+ index_start_tags (); } - public int find_next_tag_index (XmlString start, int index) {+ public int get_index (XmlString start) { int offset = (int) ((size_t) start.data - (size_t) data);+ return offset;+ }+ + public int find_next_tag_token (XmlString start, int index) {+ int offset = get_index (start); int start_index = offset + index; int new_index;+ int j = 0; if (start_index >= length) { return -1; } - assert (start.substring (index).data == substring (start_index).data);- foreach (int i in start_tags) { new_index = i - offset;- if (new_index > start_index && new_index + 1 < start.length) {- assert (start.substring (new_index, 1).to_string () == "<");+ if (new_index > start_index) { return new_index; } } - warning ("No tag found.");+ warning ("No token not found."); return -1; }