Commit 98acfb6
Index of tags in xml parser
Changed files (5)
modifieddodo.pymodifiedlibbirdxml/Tag.valamodifiedlibbirdxml/Xml.valaaddedlibbirdxml/XmlData.valamodifiedlibbirdxml/XmlString.vala
Diff
@@ -59,11 +59,13 @@ LIBS = [ if not config.POSIXVALA: LIBBIRD_XML_LIBS = [ 'glib-2.0',+ config.GEE, 'posix' ] else: LIBBIRD_XML_LIBS = [ 'posix',+ config.GEE, 'posixtypes' ] @@ -18,7 +18,7 @@ namespace Bird { * 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 class Tag : GLib.Object { 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 @@ public class Tag : GLib.Object { 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 @@ public class Tag : GLib.Object { int previous_index; unichar c, slash; int start_count = 1;+ int next_tag; if (name.length == 0) { error = true;@@ -264,9 +267,10 @@ public class Tag : GLib.Object { } 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; } @@ -70,7 +70,7 @@ internal const int WARNINGS = 1; */ 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 class XmlParser : GLib.Object { */ public XmlParser (string data) { this.input = data;- this.data = new XmlString (data, data.length);+ this.data = new XmlData (data, data.length); reparse (NONE); } new file mode 100644@@ -0,0 +1,68 @@+/*+ 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++;+ }+ }+}++}@@ -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 @@ namespace Bird { * 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;