[vala] Fix line and column counter in markup reader



commit 508e36dc7b3c2078187bf1bd1c3bdf843bd6a7b6
Author: Florian Brosch <flo brosch gmail com>
Date:   Sun Aug 8 03:37:15 2010 +0200

    Fix line and column counter in markup reader

 vala/valamarkupreader.vala |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/vala/valamarkupreader.vala b/vala/valamarkupreader.vala
index 097700c..7805e25 100644
--- a/vala/valamarkupreader.vala
+++ b/vala/valamarkupreader.vala
@@ -68,8 +68,8 @@ public class Vala.MarkupReader : Object {
 	string read_name () {
 		char* begin = current;
 		while (current < end) {
-			if (current[0] == ' ' || current[0] == '>'
-			    || current[0] == '/' || current[0] == '=') {
+			if (current[0] == ' ' || current[0] == '\t' || current[0] == '>'
+			    || current[0] == '/' || current[0] == '=' || current[0] == '\n') {
 				break;
 			}
 			unichar u = ((string) current).get_char_validated ((long) (end - current));
@@ -120,6 +120,9 @@ public class Vala.MarkupReader : Object {
 							// end of comment
 							current += 3;
 							break;
+						} else if (current[0] == '\n') {
+							line++;
+							column = 0;
 						}
 						current++;
 					}
@@ -186,8 +189,6 @@ public class Vala.MarkupReader : Object {
 			type = MarkupTokenType.TEXT;
 		}
 
-		column += (int) (current - begin);
-
 		token_end.pos = current;
 		token_end.line = line;
 		token_end.column = column - 1;
@@ -198,6 +199,7 @@ public class Vala.MarkupReader : Object {
 	string text (char end_char) {
 		StringBuilder content = new StringBuilder ();
 		char* text_begin = current;
+		char* last_linebreak = current;
 
 		while (current < end && current[0] != end_char) {
 			unichar u = ((string) current).get_char_validated ((long) (end - current));
@@ -234,7 +236,14 @@ public class Vala.MarkupReader : Object {
 					current += u.to_utf8 (null);
 				}
 			} else {
+				if (u == '\n') {
+					line++;
+					column = 0;
+					last_linebreak = current;
+				}
+
 				current += u.to_utf8 (null);
+				column++;
 			}
 		}
 
@@ -242,6 +251,8 @@ public class Vala.MarkupReader : Object {
 			content.append (((string) text_begin).ndup (current - text_begin));
 		}
 
+		column += (int) (current - last_linebreak);
+
 		return content.str;
 	}
 



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