The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Index of tags in xml parser

These changes was commited to the Birdfont repository Tue, 26 May 2015 04:12:20 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Tue, 26 May 2015 04:12:20 +0000]

Updated Files

dodo.py
libbirdxml/Tag.vala
libbirdxml/Xml.vala
libbirdxml/XmlData.vala
libbirdxml/XmlString.vala
diff --git a/dodo.py b/dodo.py
--- a/dodo.py +++ b/dodo.py @@ -59,11 +59,13 @@ 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 XmlString entire_file; + public XmlData entire_file; public int tag_index; public int attribute_index; @@ -39,19 +39,20 @@ public int refcount = 1; internal Tag (XmlString name, XmlString attributes, XmlString content, - int log_level, XmlString entire_file) { + int log_level, XmlData entire_file) { this.entire_file = entire_file; this.log_level = log_level; this.name = name; this.data = content; this.attributes = attributes; + reparse (); reparse_attributes (); } internal Tag.empty () { - entire_file = new XmlString ("", 0); + entire_file = new XmlData ("", 0); data = new XmlString ("", 0); attributes = new XmlString ("", 0); name = new XmlString ("", 0); @@ -173,8 +174,9 @@ warn ("No data in xml string."); return new Tag.empty (); } - + while (data.get_next_ascii_char (ref index, out c)) { + if (c == '<') { separator = find_next_separator (index); @@ -256,6 +258,7 @@ int previous_index; unichar c, slash; int start_count = 1; + int next_tag; if (name.length == 0) { error = true; @@ -264,9 +267,10 @@ } while (true) { - previous_index = index; + previous_index = index; + if (!data.get_next_ascii_char (ref index, out c)) { - warn (@"Unexpected end of file"); + warn ("Unexpected end of file"); break; }
--- a/libbirdxml/Xml.vala +++ b/libbirdxml/Xml.vala @@ -70,7 +70,7 @@ */ public class XmlParser : GLib.Object { public Tag root; - public XmlString data; + public XmlData data; public string input; public bool error; public int refcount = 1; @@ -81,7 +81,7 @@ */ public XmlParser (string data) { this.input = data; - this.data = new XmlString (data, data.length); + this.data = new XmlData (data, data.length); reparse (NONE); }
diff --git libbirdxml/XmlData.vala(new)
--- /dev/null +++ b/libbirdxml/XmlData.vala @@ -1,1 +1,69 @@ + /* + Copyright (C) 2015 Johan Mattsson + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + 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; + + public XmlData (char* data, int length) { + base (data, length); + start_tags = new Gee.ArrayList<int> (); + // FIXME: index index_start_tags (); + } + + public int find_next_tag_index (XmlString start, int index) { + int offset = (int) ((size_t) start.data - (size_t) data); + int start_index = offset + index; + int new_index; + + 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 () == "<"); + return new_index; + } + } + + warning ("No tag found."); + + return -1; + } + + void index_start_tags () { + const char first_bit = 1 << 7; + int i = 0; + char* d = data; + + while (d[i] != '\0') { + if ((int) (d[i] & first_bit) == 0) { + if (d[i] == '<') { + start_tags.add (i); + } + } + i++; + } + } + } + + }
--- a/libbirdxml/XmlString.vala +++ b/libbirdxml/XmlString.vala @@ -11,6 +11,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */ + + using Gee; + namespace Bird { /** @@ -18,12 +21,11 @@ * copies a pointer to string instead of the data. It is faster if the string is * huge. */ - public class XmlString : GLib.Object { - + public class XmlString : GLib.Object { public int length; public char* data; public int refcount = 1; - + internal XmlString (char* data, int length) { this.data = data; this.length = length;