The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Remove gee from XML parser

These changes was commited to the Birdfont repository Tue, 26 May 2015 15:28:37 +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 15:28:37 +0000 (17:28 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Tue, 26 May 2015 15:28:37 +0000 (17:28 +0200)
commit 586fcd6f59dca10e584ec0099dd5484963326ae0
tree ecc6e39399d1dd7ffa3574f2c53341374d73966f
parent cb334f705cb391e0b2e736a594877c807292eff5
Remove gee from XML parser

dodo.py
libbirdxml/Tag.vala
libbirdxml/XmlData.vala
libbirdxml/XmlString.vala
diff --git a/dodo.py b/dodo.py
--- a/dodo.py +++ b/dodo.py @@ -59,13 +59,11 @@ if not config.POSIXVALA: LIBBIRD_XML_LIBS = [ 'glib-2.0', - config.GEE, 'posix' ] else: LIBBIRD_XML_LIBS = [ 'posix', - config.GEE, 'posixtypes' ]
--- a/libbirdxml/Tag.vala +++ b/libbirdxml/Tag.vala @@ -18,7 +18,7 @@ * Representation of one XML tag. */ public class Tag : GLib.Object { - public XmlData entire_file; + internal XmlData entire_file; public int tag_index; public int attribute_index; @@ -265,11 +265,11 @@ warn ("No name for tag."); return -1; } - + index = entire_file.get_index (data) + start; while (true) { while (!entire_file.substring (index).has_prefix ("</")) { - index = entire_file.find_next_tag_token (entire_file, index); + index = entire_file.find_next_tag_token (index + 1); if (index == -1) { warning (@"No end tag for $(name)");
--- a/libbirdxml/XmlData.vala +++ b/libbirdxml/XmlData.vala @@ -11,18 +11,29 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */ - - using Gee; namespace Bird { public class XmlData : XmlString { - public Gee.ArrayList<int> start_tags; + int* start_tags; + int tags_capacity; + int tags_size; public XmlData (char* data, int length) { base (data, length); - start_tags = new Gee.ArrayList<int> (); + + start_tags = null; + tags_capacity = 0; + tags_size = 0; + index_start_tags (); + } + + ~XmlData () { + if (start_tags != null) { + delete start_tags; + start_tags = null; + } } public int get_index (XmlString start) { @@ -30,24 +41,24 @@ return offset; } - public int find_next_tag_token (XmlString start, int index) { - int offset = get_index (start); - int start_index = offset + index; + public int find_next_tag_token (int index) { int new_index; - int j = 0; - - if (start_index >= length) { + + if (index >= length) { return -1; } - foreach (int i in start_tags) { - new_index = i - offset; - if (new_index > start_index) { + for (int i = 0; i < tags_size; i++) { + new_index = start_tags[i]; + if (new_index >= index) { + + if (new_index == 0 && i > 0) { //FIXME:DELETE + return -1; + } + return new_index; } } - - warning ("No token not found."); return -1; } @@ -60,13 +71,79 @@ while (d[i] != '\0') { if ((int) (d[i] & first_bit) == 0) { if (d[i] == '<') { - start_tags.add (i); + add_tag (i); } } i++; + } + } + + void add_tag (int index) { + if (unlikely (tags_size == tags_capacity)) { + if (!increase_capacity ()) { + return; + } + } + + start_tags[tags_size] = index; + tags_size++; + } + + bool increase_capacity () { + int* tags; + + tags_capacity += 10; + tags = (int*) new int [tags_capacity]; + + if (tags == null) { + tags_capacity = 0; + + if (start_tags != null) { + delete start_tags; + start_tags = null; + } + + warning ("Can not allocate xml data buffer."); + return false; + } + + if (tags_size > 0) { + Posix.memcpy (tags, start_tags, tags_size * sizeof (int)); + } + + if (start_tags != null) { + delete start_tags; + } + + start_tags = tags; + + return true; + } + + public void print_all () { + XmlString s; + int i = -1; + string e; + + print("All tags:\n"); + + for (int j = 0; j < tags_size; j++) { + i = find_next_tag_token (i + 1); + + if (i > -1) { + s = substring (i); + s = s.substring (0, s.index_of (">")); + s = s.substring (0, s.index_of (" ")); + } else { + e = "error"; + s = new XmlString (e, e.length); + } + + int o = start_tags[j]; + print (s.to_string () + " : " + ((string) (data + o)).ndup (4) + @" $o $j i: $i\n"); } } } }
--- a/libbirdxml/XmlString.vala +++ b/libbirdxml/XmlString.vala @@ -11,8 +11,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */ - - using Gee; namespace Bird {