vala r1806 - in trunk: . vala



Author: juergbi
Date: Sun Sep 28 12:37:35 2008
New Revision: 1806
URL: http://svn.gnome.org/viewvc/vala?rev=1806&view=rev

Log:
2008-09-28  JÃrg Billeter  <j bitron ch>

	* vala/valasourcefile.vala:

	Support parsing from a string, patch by Andrea Del Signore,
	fixes bug 553926


Modified:
   trunk/ChangeLog
   trunk/vala/valasourcefile.vala

Modified: trunk/vala/valasourcefile.vala
==============================================================================
--- trunk/vala/valasourcefile.vala	(original)
+++ trunk/vala/valasourcefile.vala	Sun Sep 28 12:37:35 2008
@@ -69,6 +69,14 @@
 	 */
 	public weak CodeContext context { get; set; }
 
+	public string? content {
+		get { return this._content; }
+		set {
+			this._content = value;
+			this.source_array = null;
+		}
+	}
+
 	private Gee.List<UsingDirective> using_directives = new ArrayList<UsingDirective> ();
 
 	private Gee.List<CodeNode> nodes = new ArrayList<CodeNode> ();
@@ -91,6 +99,8 @@
 
 	private MappedFile mapped_file = null;
 
+	private string? _content = null;
+
 	/**
 	 * Creates a new source file.
 	 *
@@ -98,10 +108,11 @@
 	 * @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 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 @@
 	 */
 	private void read_source_file () {
 		string cont;
-		source_array = new Gee.ArrayList<string> ();
 		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> ();
 		string[] lines = cont.split ("\n", 0);
 		uint idx;
 		for (idx = 0; lines[idx] != null; ++idx) {
@@ -438,6 +458,10 @@
 	}
 
 	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 size_t get_mapped_length () {
+		if (content != null) {
+			return content.length;
+		}
+
 		return mapped_file.get_length ();
 	}
 }



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