From: Jürg Billeter Date: Sun, 28 Sep 2008 12:37:35 +0000 (+0000) Subject: Support parsing from a string, patch by Andrea Del Signore, fixes bug X-Git-Tag: VALA_0_4_0~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b65f6ab85b360108544eceea41d7b25c00cdc567;p=thirdparty%2Fvala.git Support parsing from a string, patch by Andrea Del Signore, fixes bug 2008-09-28 Jürg Billeter * vala/valasourcefile.vala: Support parsing from a string, patch by Andrea Del Signore, fixes bug 553926 svn path=/trunk/; revision=1806 --- diff --git a/ChangeLog b/ChangeLog index 04807592a..3099f62b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-09-28 Jürg Billeter + + * vala/valasourcefile.vala: + + Support parsing from a string, patch by Andrea Del Signore, + fixes bug 553926 + 2008-09-28 Jürg Billeter * vala/valainterfacewriter.vala: diff --git a/vala/valasourcefile.vala b/vala/valasourcefile.vala index bc8a69260..86757b44d 100644 --- a/vala/valasourcefile.vala +++ b/vala/valasourcefile.vala @@ -69,6 +69,14 @@ public class Vala.SourceFile { */ public weak CodeContext context { get; set; } + public string? content { + get { return this._content; } + set { + this._content = value; + this.source_array = null; + } + } + private Gee.List using_directives = new ArrayList (); private Gee.List nodes = new ArrayList (); @@ -91,6 +99,8 @@ public class Vala.SourceFile { private MappedFile mapped_file = null; + private string? _content = null; + /** * Creates a new source file. * @@ -98,10 +108,11 @@ public class Vala.SourceFile { * @param pkg true if this is a VAPI package file * @return newly created source file */ - public SourceFile (CodeContext context, string filename, bool pkg = false) { + public SourceFile (CodeContext context, string filename, bool pkg = false, string? content = null) { this.filename = filename; this.external_package = pkg; this.context = context; + this.content = content; } /** @@ -411,7 +422,11 @@ public class Vala.SourceFile { */ public string? get_source_line (int lineno) { if (source_array == null) { - read_source_file (); + if (content != null) { + read_source_lines (content); + } else { + read_source_file (); + } } if (lineno < 1 || lineno > source_array.size) { return null; @@ -424,12 +439,17 @@ public class Vala.SourceFile { */ private void read_source_file () { string cont; - source_array = new Gee.ArrayList (); try { FileUtils.get_contents (filename, out cont); } catch (FileError fe) { return; } + read_source_lines (cont); + } + + private void read_source_lines (string cont) + { + source_array = new Gee.ArrayList (); string[] lines = cont.split ("\n", 0); uint idx; for (idx = 0; lines[idx] != null; ++idx) { @@ -438,6 +458,10 @@ public class Vala.SourceFile { } public char* get_mapped_contents () { + if (content != null) { + return content; + } + if (mapped_file == null) { try { mapped_file = new MappedFile (filename, false); @@ -451,6 +475,10 @@ public class Vala.SourceFile { } public size_t get_mapped_length () { + if (content != null) { + return content.length; + } + return mapped_file.get_length (); } }