]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: Return char instead of unichar from string element access
authorJürg Billeter <j@bitron.ch>
Fri, 20 Aug 2010 19:36:59 +0000 (21:36 +0200)
committerJürg Billeter <j@bitron.ch>
Fri, 20 Aug 2010 19:36:59 +0000 (21:36 +0200)
Use string.get_char () to retrieve unichar.

codegen/valaccodearraymodule.vala
vala/valaelementaccess.vala
vapi/glib-2.0.vapi

index 9242b83fa8f727bc69356b9f06c9eb4429f779f9..dc316cb20b68e594ffb61d20421f32ae8e762697 100644 (file)
@@ -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++) {
index 42c386fdcd0b75c7b4c29db82c9b9ad606569d63..ed452ca89aca49effb415e0354d842c652e1cc94 100644 (file)
@@ -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;
index e2dfd910d7280e457a824a7da70ee43bb6ae8558..84cb635c61c8d5759f8d11503017c0e9846b324f 100644 (file)
@@ -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")]