[gxml] DOM4: Implemented DomComment on GComment



commit 70237491ec97cb8815dd1dddf453ff65234e632c
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Jul 13 17:06:31 2016 -0500

    DOM4: Implemented DomComment on GComment

 gxml/DomCharacter.vala  |    8 ++++----
 gxml/GXmlAttribute.vala |    2 ++
 gxml/GXmlComment.vala   |   39 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 5 deletions(-)
---
diff --git a/gxml/DomCharacter.vala b/gxml/DomCharacter.vala
index ac07abc..50bb76c 100644
--- a/gxml/DomCharacter.vala
+++ b/gxml/DomCharacter.vala
@@ -26,11 +26,11 @@ public interface GXml.DomCharacterData : GLib.Object, GXml.DomNode, GXml.DomNonD
         */
   public abstract string data { get; set; }
   public abstract ulong length { get; }
-  public abstract string substring_data (ulong offset, ulong count);
+  public abstract string substring_data (ulong offset, ulong count) throws GLib.Error;
   public abstract void append_data  (string data);
-  public abstract void insert_data  (ulong offset, string data);
-  public abstract void delete_data  (ulong offset, ulong count);
-  public abstract void replace_data (ulong offset, ulong count, string data);
+  public abstract void insert_data  (ulong offset, string data) throws GLib.Error;
+  public abstract void delete_data  (ulong offset, ulong count) throws GLib.Error;
+  public abstract void replace_data (ulong offset, ulong count, string data) throws GLib.Error;
 }
 
 public interface GXml.DomText : GXml.DomCharacterData {
diff --git a/gxml/GXmlAttribute.vala b/gxml/GXmlAttribute.vala
index a32e371..f5a5376 100644
--- a/gxml/GXmlAttribute.vala
+++ b/gxml/GXmlAttribute.vala
@@ -103,6 +103,8 @@ public class GXml.GAttribute : GXml.GNode, GXml.Attribute, GXml.DomAttr
   public string GXml.DomAttr.name {
     get {
       if (namespace == null) return (this as GXml.Node).name;
+      string s = namespace.prefix+":"+(this as GXml.Node).name;
+      return s;
     }
   }
   public string @value {
diff --git a/gxml/GXmlComment.vala b/gxml/GXmlComment.vala
index f3fe50f..77a3175 100644
--- a/gxml/GXmlComment.vala
+++ b/gxml/GXmlComment.vala
@@ -24,7 +24,7 @@ using Gee;
 /**
  * Class implemeting {@link GXml.Comment} interface, not tied to libxml-2.0 library.
  */
-public class GXml.GComment : GXml.GNode, GXml.Comment
+public class GXml.GComment : GXml.GNode, GXml.Comment, GXml.DomCharacterData, GXml.DomComment
 {
   public GComment (GDocument doc, Xml.Node *node)
   {
@@ -38,4 +38,41 @@ public class GXml.GComment : GXml.GNode, GXml.Comment
   }
   // GXml.Comment
   public string str { owned get { return base.value; } }
+
+  public string data {
+    get {
+      return str;
+    }
+    set {
+      str = value;
+    }
+  }
+  public ulong length { get { return str.length; } }
+  public string substring_data (ulong offset, ulong count) throws GLib.Error {
+    if (((int)offset) > str.length)
+      throw new DomError.INDEX_SIZE_ERROR (_("Invalid offset for substring"));
+    int c = (int) count;
+    if (c > str.length) c = str.length;
+    return str[(int)offset:(int)c];
+  }
+  public void append_data  (string data) {
+    str += data;
+  }
+  public void insert_data  (ulong offset, string data) throws GLib.Error {
+    replace_data (offset, 0, data);
+  }
+  public void delete_data  (ulong offset, ulong count) throws GLib.Error {
+    replace_data (offset, count, "");
+  }
+  public void replace_data (ulong offset, ulong count, string data) throws GLib.Error {
+    if (((int)offset) > str.length)
+      throw new DomError.INDEX_SIZE_ERROR (_("Invalid offset for replace data"));
+    int c = (int) count;
+    if (((int)offset + c) > str.length) c = str.length - (int)offset;
+
+    string s = str[0:(int)offset];
+    string s2 = str[0:(s.length - (int)offset - c)];
+    string sr = data[0:(int)count];
+    str = s+sr+s2;
+  }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]