The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Find end tag in xml parser index

These changes was commited to the Birdfont repository Tue, 26 May 2015 06:38:27 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Tue, 26 May 2015 06:38:27 +0000 (08:38 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Tue, 26 May 2015 06:43:25 +0000 (08:43 +0200)
commit 84ed66a8f49e923b3e489d1e7ab446658898de83
tree ec4fee4d97f069fb3864ced8df1db12a8d90085e
parent 98acfb64ccba9c615580ea38bc3782026854da43
Find end tag in xml parser index

libbirdxml/Tag.vala
libbirdxml/XmlData.vala
--- a/libbirdxml/Tag.vala +++ b/libbirdxml/Tag.vala @@ -265,19 +265,30 @@ 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 @@ return previous_index; } } - } else if (is_tag (name, index)) { + } else if (entire_file.substring (index).has_prefix (name.to_string ())) { start_count++; } }
--- a/libbirdxml/XmlData.vala +++ b/libbirdxml/XmlData.vala @@ -22,29 +22,32 @@ 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; }