]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: Deprecate string.len () in favor of string.length
authorJürg Billeter <j@bitron.ch>
Fri, 20 Aug 2010 18:04:59 +0000 (20:04 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 4 Sep 2010 14:57:26 +0000 (16:57 +0200)
21 files changed:
codegen/valaccodebasemodule.vala
codegen/valadovabasemodule.vala
codegen/valagtypemodule.vala
compiler/valacompiler.vala
vala/valacharacterliteral.vala
vala/valaclass.vala
vala/valaenumvalue.vala
vala/valagenieparser.vala
vala/valageniescanner.vala
vala/valagirparser.vala
vala/valainterface.vala
vala/valaparser.vala
vala/valaproperty.vala
vala/valascanner.vala
vala/valasignal.vala
vala/valasourcefile.vala
vala/valastringliteral.vala
vala/valasymbol.vala
vapi/glib-2.0.vapi
vapigen/valagidlparser.vala
vapigen/valavapigen.vala

index 6a17886dc423a0af52946d3089fd35fe9a88da08..2b9a9ab9a2cacc2efb8ac790c415ee39c610dbd1 100644 (file)
@@ -719,7 +719,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
                var define = new StringBuilder ("__");
                
                var i = filename;
-               while (i.len () > 0) {
+               while (i.length > 0) {
                        var c = i.get_char ();
                        if (c.isalnum  () && c < 0x80) {
                                define.append_unichar (c.toupper ());
index 2a45d2840f2fd3e714f8e88516e9e301838c322f..5feabfd7d4afce77f4fe696841744be1d81d20f2 100644 (file)
@@ -398,7 +398,7 @@ public class Vala.DovaBaseModule : CodeGenerator {
                var define = new StringBuilder ("__");
 
                var i = filename;
-               while (i.len () > 0) {
+               while (i.length > 0) {
                        var c = i.get_char ();
                        if (c.isalnum  () && c < 0x80) {
                                define.append_unichar (c.toupper ());
index b2310e70553da6238f744229dee7103ace287e83..7e45efe8597871f2c0b407285a5bad44168d2768 100644 (file)
@@ -526,7 +526,7 @@ public class Vala.GTypeModule : GErrorModule {
                bool is_gtypeinstance = !cl.is_compact;
                bool is_fundamental = is_gtypeinstance && cl.base_class == null;
 
-               if (cl.get_cname().len () < 3) {
+               if (cl.get_cname().length < 3) {
                        cl.error = true;
                        Report.error (cl.source_reference, "Class name `%s' is too short".printf (cl.get_cname ()));
                        return;
@@ -1937,7 +1937,7 @@ public class Vala.GTypeModule : GErrorModule {
        public override void visit_interface (Interface iface) {
                push_context (new EmitContext (iface));
 
-               if (iface.get_cname().len () < 3) {
+               if (iface.get_cname().length < 3) {
                        iface.error = true;
                        Report.error (iface.source_reference, "Interface name `%s' is too short".printf (iface.get_cname ()));
                        return;
index 4c52866c80f35c522041825594a34a38244ed84c..9536ba7bafc3bcf7ac1d5d41ca0056ff53c65530 100644 (file)
@@ -460,7 +460,7 @@ class Vala.Compiler {
                if (library != null) {
                        if (gir != null) {
                                if (context.profile == Profile.GOBJECT) {
-                                       long gir_len = gir.len ();
+                                       long gir_len = gir.length;
                                        unowned string? last_hyphen = gir.rchr (gir_len, '-');
 
                                        if (last_hyphen == null || !gir.has_suffix (".gir")) {
@@ -541,7 +541,7 @@ class Vala.Compiler {
        }
 
        private static bool ends_with_dir_separator (string s) {
-               return Path.is_dir_separator (s.offset (s.len () - 1).get_char ());
+               return Path.is_dir_separator (s.offset (s.length - 1).get_char ());
        }
 
        /* ported from glibc */
@@ -586,9 +586,9 @@ class Vala.Compiler {
                                // do nothing
                        } else if (len == 2 && start.has_prefix ("..")) {
                                // back up to previous component, ignore if at root already
-                               if (rpath.len () > root_len) {
+                               if (rpath.length > root_len) {
                                        do {
-                                               rpath = rpath.substring (0, rpath.len () - 1);
+                                               rpath = rpath.substring (0, rpath.length - 1);
                                        } while (!ends_with_dir_separator (rpath));
                                }
                        } else {
@@ -600,8 +600,8 @@ class Vala.Compiler {
                        }
                }
 
-               if (rpath.len () > root_len && ends_with_dir_separator (rpath)) {
-                       rpath = rpath.substring (0, rpath.len () - 1);
+               if (rpath.length > root_len && ends_with_dir_separator (rpath)) {
+                       rpath = rpath.substring (0, rpath.length - 1);
                }
 
                if (Path.DIR_SEPARATOR != '/') {
index 0de991872de2ae53b642fa42f347dd4b9a2d0a57..d368d7d01060687798fdda777d6ff1c293bee04b 100644 (file)
@@ -38,7 +38,7 @@ public class Vala.CharacterLiteral : Literal {
                set {
                        _value = value;
                        
-                       if (!value.validate () || (value.len () != 3 && value.next_char ().get_char () != '\\')) {
+                       if (!value.validate () || (value.length != 3 && value.next_char ().get_char () != '\\')) {
                                error = true;
                        }
                }
index 1fb579833ae6d810c29a6b0611ea21028efdeb7d..0380acb76b6cab60a2290d3adee8f06865d91c75 100644 (file)
@@ -595,12 +595,12 @@ public class Vala.Class : ObjectTypeSymbol {
 
                        // remove underscores in some cases to avoid conflicts of type macros
                        if (lower_case_csuffix.has_prefix ("type_")) {
-                               lower_case_csuffix = "type" + lower_case_csuffix.offset ("type_".len ());
+                               lower_case_csuffix = "type" + lower_case_csuffix.offset ("type_".length);
                        } else if (lower_case_csuffix.has_prefix ("is_")) {
-                               lower_case_csuffix = "is" + lower_case_csuffix.offset ("is_".len ());
+                               lower_case_csuffix = "is" + lower_case_csuffix.offset ("is_".length);
                        }
                        if (lower_case_csuffix.has_suffix ("_class")) {
-                               lower_case_csuffix = lower_case_csuffix.substring (0, lower_case_csuffix.len () - "_class".len ()) + "class";
+                               lower_case_csuffix = lower_case_csuffix.substring (0, lower_case_csuffix.length - "_class".length) + "class";
                        }
                }
                return lower_case_csuffix;
index 2ade411bd8b1c0d60ab5c0c82e060f49734b1c32..973bc554e2eb3734462e32a1d6cf34ee62f2431e 100644 (file)
@@ -48,7 +48,7 @@ public class Vala.EnumValue : Constant {
 
                string i = name;
 
-               while (i.len () > 0) {
+               while (i.length > 0) {
                        unichar c = i.get_char ();
                        if (c == '_') {
                                str.append_c ('-');
index 20e2263cc45fa542e66dce01e3d090aacd378845..415a9fed34819470175216e08fe68db11afbf8fc 100644 (file)
@@ -363,7 +363,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                case TokenType.VERBATIM_STRING_LITERAL:
                        next ();
                        string raw_string = get_last_string ();
-                       string escaped_string = raw_string.substring (3, raw_string.len () - 6).escape ("");
+                       string escaped_string = raw_string.substring (3, raw_string.length - 6).escape ("");
                        return new StringLiteral ("\"%s\"".printf (escaped_string), get_src (begin));   
                case TokenType.NULL:
                        next ();
index 87e9b457b13975cda40a5d37503e3710106a6344..a590dad8e90c5d052fa4d70abd8c4f018d7c5d18 100644 (file)
@@ -1391,7 +1391,7 @@ public class Vala.Genie.Scanner {
 
        bool matches (char* begin, string keyword) {
                char* keyword_array = (char *) keyword;
-               long len = keyword.len ();
+               long len = keyword.length;
                for (int i = 0; i < len; i++) {
                        if (begin[i] != keyword_array[i]) {
                                return false;
index b9965964b79825c551986362b5f7c2b0249f4900..2ea8ee415ddd25e10e952acedea8e405a46ad49a 100644 (file)
@@ -307,7 +307,7 @@ public class Vala.GirParser : CodeVisitor {
        private void calculate_common_prefix (ref string common_prefix, string cname) {
                if (common_prefix == null) {
                        common_prefix = cname;
-                       while (common_prefix.len () > 0 && !common_prefix.has_suffix ("_")) {
+                       while (common_prefix.length > 0 && !common_prefix.has_suffix ("_")) {
                                // FIXME: could easily be made faster
                                common_prefix = common_prefix.ndup (common_prefix.size () - 1);
                        }
@@ -316,8 +316,8 @@ public class Vala.GirParser : CodeVisitor {
                                common_prefix = common_prefix.ndup (common_prefix.size () - 1);
                        }
                }
-               while (common_prefix.len () > 0 && (!common_prefix.has_suffix ("_") ||
-                      (cname.offset (common_prefix.length).get_char ().isdigit ()) && (cname.len () - common_prefix.len ()) <= 1)) {
+               while (common_prefix.length > 0 && (!common_prefix.has_suffix ("_") ||
+                      (cname.offset (common_prefix.length).get_char ().isdigit ()) && (cname.length - common_prefix.length) <= 1)) {
                        // enum values may not consist solely of digits
                        common_prefix = common_prefix.ndup (common_prefix.size () - 1);
                }
@@ -1018,7 +1018,7 @@ public class Vala.GirParser : CodeVisitor {
                if (m.name == "new") {
                        m.name = null;
                } else if (m.name.has_prefix ("new_")) {
-                       m.name = m.name.offset ("new_".len ());
+                       m.name = m.name.offset ("new_".length);
                }
                if (current_token == MarkupTokenType.START_ELEMENT && reader.name == "parameters") {
                        start_element ("parameters");
index 02c63a8460e394287bfc4d5ca3786d82bd2d007b..f2339542bf17617b0286f84583842c90200de510 100644 (file)
@@ -321,12 +321,12 @@ public class Vala.Interface : ObjectTypeSymbol {
 
                // remove underscores in some cases to avoid conflicts of type macros
                if (result.has_prefix ("type_")) {
-                       result = "type" + result.offset ("type_".len ());
+                       result = "type" + result.offset ("type_".length);
                } else if (result.has_prefix ("is_")) {
-                       result = "is" + result.offset ("is_".len ());
+                       result = "is" + result.offset ("is_".length);
                }
                if (result.has_suffix ("_class")) {
-                       result = result.substring (0, result.len () - "_class".len ()) + "class";
+                       result = result.substring (0, result.length - "_class".length) + "class";
                }
 
                return result;
index 8d375cc787e96a5cbe11bc4fff454c56b644b2c5..f7dc50b35c4cc5e63b0a61d0419bff0b650267bb 100644 (file)
@@ -308,7 +308,7 @@ public class Vala.Parser : CodeVisitor {
                case TokenType.VERBATIM_STRING_LITERAL:
                        next ();
                        string raw_string = get_last_string ();
-                       string escaped_string = raw_string.substring (3, raw_string.len () - 6).escape ("");
+                       string escaped_string = raw_string.substring (3, raw_string.length - 6).escape ("");
                        return new StringLiteral ("\"%s\"".printf (escaped_string), get_src (begin));
                case TokenType.NULL:
                        next ();
index 7621099c768d5419fdbe4e4b4da274ee3de7a7b2..f2024442afc79184310cfc384e896a907f3a4dc1 100644 (file)
@@ -250,7 +250,7 @@ public class Vala.Property : Symbol, Lockable {
                
                string i = name;
                
-               while (i.len () > 0) {
+               while (i.length > 0) {
                        unichar c = i.get_char ();
                        if (c == '_') {
                                str.append_c ('-');
index e5fd0db7a0d12f42d4ff34fbec39d3e3f5a91560..d5dc063d0c2146d458807802553fcebdf2dccdea 100644 (file)
@@ -1193,7 +1193,7 @@ public class Vala.Scanner {
 
        static bool matches (char* begin, string keyword) {
                char* keyword_array = (char*) keyword;
-               long len = keyword.len ();
+               long len = keyword.length;
                for (int i = 0; i < len; i++) {
                        if (begin[i] != keyword_array[i]) {
                                return false;
index 926c75fbbd754f84a91127648aecf917bf9ad029..2bd1d3f3a598d29e49b2a11460a2b1231a7240b6 100644 (file)
@@ -174,7 +174,7 @@ public class Vala.Signal : Symbol, Lockable {
                
                string i = get_cname ();
                
-               while (i.len () > 0) {
+               while (i.length > 0) {
                        unichar c = i.get_char ();
                        if (c == '_') {
                                str.append_c ('-');
index 464c93e2dc38234eac64405d36d729352e698f32..e58e009d4e08bb4223f4f228762e25acdabe0b83 100644 (file)
@@ -170,7 +170,7 @@ public class Vala.SourceFile {
                // filename and basedir are already canonicalized
                if (filename.has_prefix (context.basedir + "/")) {
                        var basename = Path.get_basename (filename);
-                       var subdir = filename.substring (context.basedir.len (), filename.len () - context.basedir.len () - basename.len ());
+                       var subdir = filename.substring (context.basedir.length, filename.length - context.basedir.length - basename.length);
                        while (subdir[0] == '/') {
                                subdir = subdir.offset (1);
                        }
index 2a1cbc79f4d0153474ceadc88654f620b1bfdf99..e0234bd302d04a8130954a39e230ea6f94e6f7a9 100644 (file)
@@ -54,7 +54,7 @@ public class Vala.StringLiteral : Literal {
                }
                
                /* remove quotes */
-               var noquotes = value.substring (1, (uint) (value.len () - 2));
+               var noquotes = value.substring (1, (uint) (value.length - 2));
                /* unescape string */
                return noquotes.compress ();
        }
index 57a0e9e1cff605bfa44a73b75828b0b4caeff32d..a935bcb76c6cdd6a1a00c2c341eb850ad02589c5 100644 (file)
@@ -282,7 +282,7 @@ public abstract class Vala.Symbol : CodeNode {
                weak string i = camel_case;
 
                bool first = true;
-               while (i.len () > 0) {
+               while (i.length > 0) {
                        unichar c = i.get_char ();
                        if (c.isupper () && !first) {
                                /* current character is upper case and
@@ -291,10 +291,10 @@ public abstract class Vala.Symbol : CodeNode {
                                bool prev_upper = t.get_char ().isupper ();
                                t = i.next_char ();
                                bool next_upper = t.get_char ().isupper ();
-                               if (!prev_upper || (i.len () >= 2 && !next_upper)) {
+                               if (!prev_upper || (i.length >= 2 && !next_upper)) {
                                        /* previous character wasn't upper case or
                                         * next character isn't upper case*/
-                                       long len = result_builder.str.len ();
+                                       long len = result_builder.str.length;
                                        if (len != 1 && result_builder.str.offset (len - 2).get_char () != '_') {
                                                /* we're not creating 1 character words */
                                                result_builder.append_c ('_');
@@ -323,7 +323,7 @@ public abstract class Vala.Symbol : CodeNode {
                weak string i = lower_case;
 
                bool last_underscore = true;
-               while (i.len () > 0) {
+               while (i.length > 0) {
                        unichar c = i.get_char ();
                        if (c == '_') {
                                last_underscore = true;
index 17031946f952fa878812e3cd47a81ab2a744e144..de5204188846ce3e91da74fae87abc962ecb4782 100644 (file)
@@ -976,6 +976,7 @@ public class string {
        public long pointer_to_offset (string pos);
        [CCode (cname = "g_utf8_prev_char")]
        public unowned string prev_char ();
+       [Deprecated (replacement = "string.length")]
        [CCode (cname = "g_utf8_strlen")]
        public long len (ssize_t max = -1);
        [CCode (cname = "g_utf8_strchr")]
@@ -1083,7 +1084,7 @@ public class string {
        public string ndup (size_t n);
 
        public string substring (long offset, long len = -1) {
-               long string_length = this.len ();
+               long string_length = this.length;
                if (offset < 0) {
                        offset = string_length + offset;
                        GLib.return_val_if_fail (offset >= 0, null);
@@ -1099,7 +1100,7 @@ public class string {
        }
 
        public string slice (long start, long end) {
-               long string_length = this.len ();
+               long string_length = this.length;
                if (start < 0) {
                        start = string_length + start;
                }
@@ -1114,7 +1115,7 @@ public class string {
        }
 
        public string splice (long start, long end, string? str = null) {
-               long string_length = this.len ();
+               long string_length = this.length;
                if (start < 0) {
                        start = string_length + start;
                }
@@ -1162,8 +1163,11 @@ public class string {
                }
        }
 
+       [CCode (cname = "g_utf8_strlen")]
+       long utf8_strlen (ssize_t max);
+
        public long length {
-               get { return this.len (); }
+               get { return this.utf8_strlen (-1); }
        }
 
        public uint8[] data {
index 62ba63c3a0448cd5a885f1ffefdb0af451e1c463..e9b518d03a087318ae693a1cdfd913336a0c4431 100644 (file)
@@ -162,20 +162,20 @@ public class Vala.GIdlParser : CodeVisitor {
                }
 
                if (type_name.has_prefix (ns.name)) {
-                       return type_name.offset (ns.name.len ());
+                       return type_name.offset (ns.name.length);
                } else if (ns.name == "GLib" && type_name.has_prefix ("G")) {
                        return type_name.offset (1);
                } else  {
                        string best_match = null;
                        foreach (string cprefix in ns.get_cprefixes ()) {
                                if (type_name.has_prefix (cprefix)) {
-                                       if (best_match == null || cprefix.len () > best_match.len ())
+                                       if (best_match == null || cprefix.length > best_match.length)
                                                best_match = cprefix;
                                }
                        }
 
                        if (best_match != null) {
-                               return type_name.offset (best_match.len ());;
+                               return type_name.offset (best_match.length);;
                        }
                }
 
@@ -184,7 +184,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
        private string fix_const_name (string const_name, Namespace ns) {
                if (const_name.has_prefix (ns.name.up () + "_")) {
-                       return const_name.offset (ns.name.len () + 1);
+                       return const_name.offset (ns.name.length + 1);
                } else if (ns.name == "GLib" && const_name.has_prefix ("G_")) {
                        return const_name.offset (2);
                }
@@ -1010,7 +1010,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
                        if (common_prefix == null) {
                                common_prefix = value.name;
-                               while (common_prefix.len () > 0 && !common_prefix.has_suffix ("_")) {
+                               while (common_prefix.length > 0 && !common_prefix.has_suffix ("_")) {
                                        // FIXME: could easily be made faster
                                        common_prefix = common_prefix.ndup (common_prefix.size () - 1);
                                }
@@ -1019,8 +1019,8 @@ public class Vala.GIdlParser : CodeVisitor {
                                        common_prefix = common_prefix.ndup (common_prefix.size () - 1);
                                }
                        }
-                       while (common_prefix.len () > 0 && (!common_prefix.has_suffix ("_") ||
-                              (value.name.offset (common_prefix.length).get_char ().isdigit ()) && (value.name.len () - common_prefix.len ()) <= 1)) {
+                       while (common_prefix.length > 0 && (!common_prefix.has_suffix ("_") ||
+                              (value.name.offset (common_prefix.length).get_char ().isdigit ()) && (value.name.length - common_prefix.length) <= 1)) {
                                // enum values may not consist solely of digits
                                common_prefix = common_prefix.ndup (common_prefix.size () - 1);
                        }
@@ -1084,7 +1084,7 @@ public class Vala.GIdlParser : CodeVisitor {
                        }
 
                        if (!is_hidden) {
-                               var ev = new EnumValue (value2.name.offset (common_prefix.len ()), null);
+                               var ev = new EnumValue (value2.name.offset (common_prefix.length), null);
                                en.add_value (ev);
                        }
                }
@@ -1456,7 +1456,7 @@ public class Vala.GIdlParser : CodeVisitor {
                        }
                        
                        if (n.has_prefix ("const-")) {
-                               n = n.offset ("const-".len ());
+                               n = n.offset ("const-".length);
                        }
 
                        if (type_node.is_pointer &&
@@ -1567,7 +1567,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                var nv = attr.split ("=", 2);
 
                                if (nv[0] == "cprefix") {
-                                       type.unresolved_symbol = new UnresolvedSymbol (null, n.offset (eval (nv[1]).len ()));
+                                       type.unresolved_symbol = new UnresolvedSymbol (null, n.offset (eval (nv[1]).length));
                                } else if (nv[0] == "name") {
                                        type.unresolved_symbol = new UnresolvedSymbol (null, eval (nv[1]));
                                } else if (nv[0] == "namespace") {
@@ -1589,7 +1589,7 @@ public class Vala.GIdlParser : CodeVisitor {
                }
 
                if (n.has_prefix (current_namespace.name)) {
-                       type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, current_namespace.name), n.offset (current_namespace.name.len ()));
+                       type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, current_namespace.name), n.offset (current_namespace.name.length));
                } else if (n.has_prefix ("G")) {
                        type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, "GLib"), n.offset (1));
                } else {
@@ -1622,7 +1622,7 @@ public class Vala.GIdlParser : CodeVisitor {
                }
 
                if (type_arg.has_prefix ("unowned ")) {
-                       type_arg = type_arg.offset ("unowned ".len ());
+                       type_arg = type_arg.offset ("unowned ".length);
                        is_unowned = true;
                }
 
@@ -1649,7 +1649,7 @@ public class Vala.GIdlParser : CodeVisitor {
                        if (m.name == "new") {
                                m.name = null;
                        } else if (m.name.has_prefix ("new_")) {
-                               m.name = m.name.offset ("new_".len ());
+                               m.name = m.name.offset ("new_".length);
                        }
                        // For classes, check whether a creation method return type equals to the
                        // type of the class created. If the types do not match (e.g. in most
@@ -1806,7 +1806,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                        // class method
                                        m.binding = MemberBinding.CLASS;
                                        if (m.name.has_prefix ("class_")) {
-                                               m.name = m.name.substring ("class_".len (), m.name.len () - "class_".len ());
+                                               m.name = m.name.substring ("class_".length, m.name.length - "class_".length);
                                        }
                                        continue;
                                } else {
@@ -1949,7 +1949,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                                        p.initializer = new StringLiteral ("\"\"", param_type.source_reference);
                                                } else {
                                                        unowned string endptr;
-                                                       unowned string val_end = val.offset (val.len ());
+                                                       unowned string val_end = val.offset (val.length);
 
                                                        val.to_long (out endptr);
                                                        if ((long)endptr == (long)val_end) {
@@ -2086,7 +2086,7 @@ public class Vala.GIdlParser : CodeVisitor {
                
                string i = name;
                
-               while (i.len () > 0) {
+               while (i.length > 0) {
                        unichar c = i.get_char ();
                        if (c == '-') {
                                str.append_c ('_');
@@ -2378,7 +2378,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
                GLib.SList<string> attr_list = new GLib.SList<string> ();
                var attr = new GLib.StringBuilder.sized (attributes.size ());
-               var attributes_len = attributes.len ();
+               var attributes_len = attributes.length;
                unowned string remaining = attributes;
                bool quoted = false, escaped = false;
                for (int b = 0 ; b < attributes_len ; b++) {
index 686102a3534ce5b0f913c02a8499c6e558ceae41..403fa89f4a88e04f2ac93f65ce9b787df31b4952 100644 (file)
@@ -131,7 +131,7 @@ class Vala.VAPIGen : Object {
                                continue;
                        }
 
-                       var depsfile = source.substring (0, source.len () - "gi".len ()) + "deps";
+                       var depsfile = source.substring (0, source.length - "gi".length) + "deps";
 
                        if (!FileUtils.test (depsfile, FileTest.EXISTS)) continue;