[gxml] Parser added read_string_async()



commit 2e0341e13130508c788463f942ff15d03e8517fd
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Jul 10 19:02:00 2017 -0500

    Parser added read_string_async()

 gxml/Parser.vala  |    9 +++++++--
 gxml/XParser.vala |    8 ++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/gxml/Parser.vala b/gxml/Parser.vala
index b0b95d7..1cea634 100644
--- a/gxml/Parser.vala
+++ b/gxml/Parser.vala
@@ -97,13 +97,18 @@ public interface GXml.Parser : Object {
   /**
    * Read a {@link GXml.DomDocument} from a {@link GLib.InputStream}
    */
-  public async abstract void read_stream_async (InputStream stream,
+  public abstract async abstract void read_stream_async (InputStream stream,
                                    GLib.Cancellable? cancellable) throws GLib.Error;
   /**
-   * Read a {@link GXml.DomDocument} from a {@link GLib.File}
+   * Reads a {@link node} from a string
    */
   public abstract void read_string (string str,
                                    GLib.Cancellable? cancellable) throws GLib.Error;
+
+  /**
+   * Reads synchronically {@link node} a from a string
+   */
+  public abstract async void read_string_async (string str, GLib.Cancellable? cancellable) throws GLib.Error;
   /**
    * Creates an {@link GLib.InputStream} to write a string representation
    * in XML
diff --git a/gxml/XParser.vala b/gxml/XParser.vala
index 51f40db..fab69b8 100644
--- a/gxml/XParser.vala
+++ b/gxml/XParser.vala
@@ -108,6 +108,14 @@ public class GXml.XParser : Object, GXml.Parser {
     var stream = new GLib.MemoryInputStream.from_data (str.data);
     read_stream (stream, cancellable);
   }
+  public async void read_string_async (string str, GLib.Cancellable? cancellable) throws GLib.Error {
+    if (str == "")
+      throw new ParserError.INVALID_DATA_ERROR (_("Invalid document string, it is empty or is not allowed"));
+    var stream = new GLib.MemoryInputStream.from_data (str.data);
+    Idle.add (read_string_async.callback);
+    yield;
+    yield read_stream_async (stream, cancellable);
+  }
 
 
   public void read_stream (GLib.InputStream istream,


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