[vala] glib-2.0: Return char instead of unichar from string element access



commit 827834613273d42b97a1ba61e293763dd2e45ead
Author: Jürg Billeter <j bitron ch>
Date:   Fri Aug 20 21:36:59 2010 +0200

    glib-2.0: Return char instead of unichar from string element access
    
    Use string.get_char () to retrieve unichar.

 codegen/valaccodearraymodule.vala |   12 ------------
 vala/valaelementaccess.vala       |    8 --------
 vapi/glib-2.0.vapi                |    4 ++++
 3 files changed, 4 insertions(+), 20 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 9242b83..dc316cb 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -397,8 +397,6 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 		List<Expression> indices = expr.get_indices ();
 		int rank = indices.size;
 
-		var container_type = expr.container.value_type.data_type;
-
 		var ccontainer = (CCodeExpression) expr.container.ccodenode;
 		var cindex = (CCodeExpression) indices[0].ccodenode;
 		if (expr.container.symbol_reference is ArrayLengthField) {
@@ -411,16 +409,6 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 			} else {
 				Report.error (expr.source_reference, "only integer literals supported as index");
 			}
-		} else if (container_type == string_type.data_type) {
-			// should be moved to a different module
-
-			// access to unichar in a string
-			var coffset = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, ccontainer, cindex);
-
-			var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_utf8_get_char"));
-			ccall.add_argument (coffset);
-
-			expr.ccodenode = ccall;
 		} else {
 			// access to element in an array
 			for (int i = 1; i < rank; i++) {
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index 42c386f..ed452ca 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -144,14 +144,6 @@ public class Vala.ElementAccess : Expression {
 			}
 		} else if (pointer_type != null && !pointer_type.base_type.is_reference_type_or_type_parameter ()) {
 			value_type = pointer_type.base_type.copy ();
-		} else if (analyzer.context.profile == Profile.GOBJECT && container_type == analyzer.string_type.data_type) {
-			if (get_indices ().size != 1) {
-				error = true;
-				Report.error (source_reference, "Element access with more than one dimension is not supported for strings");
-				return false;
-			}
-
-			value_type = analyzer.unichar_type;
 		} else if (analyzer.context.profile == Profile.DOVA && container_type == analyzer.tuple_type.data_type) {
 			if (get_indices ().size != 1) {
 				error = true;
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index e2dfd91..84cb635 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -964,6 +964,10 @@ public class string {
 	[CCode (cname = "g_strnfill")]
 	public static string nfill (size_t length, char fill_char);
 
+	public char get (long index) {
+		return ((char*) this)[index];
+	}
+
 	[CCode (cname = "g_utf8_next_char")]
 	public unowned string next_char ();
 	[CCode (cname = "g_utf8_get_char")]



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