]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: Add string.index_of_nth_char
authorJürg Billeter <j@bitron.ch>
Sat, 15 Jan 2011 19:57:07 +0000 (20:57 +0100)
committerJürg Billeter <j@bitron.ch>
Sat, 15 Jan 2011 20:00:40 +0000 (21:00 +0100)
This deprecates string.utf8_offset, string.offset,
string.pointer_to_offset, and string.ndup.

19 files changed:
codegen/valagirwriter.vala
compiler/valacompiler.vala
vala/valaclass.vala
vala/valacodecontext.vala
vala/valagenieparser.vala
vala/valageniescanner.vala
vala/valagirparser.vala
vala/valaintegerliteral.vala
vala/valainterface.vala
vala/valamarkupreader.vala
vala/valamethod.vala
vala/valaparser.vala
vala/valascanner.vala
vala/valasemanticanalyzer.vala
vala/valasourcefile.vala
vala/valasymbol.vala
vapi/glib-2.0.vapi
vapigen/valagidlparser.vala
vapigen/valavapigen.vala

index 394af0349f2265dda297406b6877ea7e9050c0d6..f6b999fdd68967b2f37680184832bc75e40a1d6c 100644 (file)
@@ -735,7 +735,7 @@ public class Vala.GIRWriter : CodeVisitor {
                        name = m.get_cname ();
                        var parent_prefix = parent.get_lower_case_cprefix ();
                        if (name.has_prefix (parent_prefix)) {
-                               name = name.offset (parent_prefix.length);
+                               name = name.substring (parent_prefix.length);
                        }
                } else {
                        name = m.name;
index ae88a6b0fb098300513af86a4c9eb5c12706d329..1a4a9df19038ab8b1b6fee38a73ef300271f9c60 100644 (file)
@@ -160,7 +160,7 @@ class Vala.Compiler {
                        // strip extension if there is one
                        // else we use the default output file of the C compiler
                        if (sources[0].rchr (-1, '.') != null) {
-                               long dot = sources[0].pointer_to_offset (sources[0].rchr (-1, '.'));
+                               long dot = (long) ((char*) sources[0].rchr (-1, '.') - (char*) sources[0]);
                                output = Path.get_basename (sources[0].substring (0, dot));
                        }
                }
@@ -380,7 +380,7 @@ class Vala.Compiler {
                                        if (last_hyphen == null || !gir.has_suffix (".gir")) {
                                                Report.error (null, "GIR file name `%s' is not well-formed, expected NAME-VERSION.gir".printf (gir));
                                        } else {
-                                               long offset = gir.pointer_to_offset (last_hyphen);
+                                               long offset = (long) ((char*) last_hyphen - (char*) gir);
                                                string gir_namespace = gir.substring (0, offset);
                                                string gir_version = gir.substring (offset + 1, gir_len - offset - 5);
                                                gir_version.canon ("0123456789.", '?');
index 0ba80329dfa412e0c6749c50b9c135019be24c36..d38135ce18778ffdecbdca3e9d5b306fad8ca280 100644 (file)
@@ -631,9 +631,9 @@ 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_".length);
+                               lower_case_csuffix = "type" + lower_case_csuffix.substring ("type_".length);
                        } else if (lower_case_csuffix.has_prefix ("is_")) {
-                               lower_case_csuffix = "is" + lower_case_csuffix.offset ("is_".length);
+                               lower_case_csuffix = "is" + lower_case_csuffix.substring ("is_".length);
                        }
                        if (lower_case_csuffix.has_suffix ("_class")) {
                                lower_case_csuffix = lower_case_csuffix.substring (0, lower_case_csuffix.length - "_class".length) + "class";
index cfb0a9bbc23b5b64044c22121c2ad840c52b08ae..30d05f391a26f8c3ff8e8ffd1e4207ff7762d71d 100644 (file)
@@ -421,7 +421,7 @@ public class Vala.CodeContext {
 
                        add_source_file (source_file);
                        // look for a local .deps
-                       var deps_filename = "%s.deps".printf (filename.ndup (filename.length - ".vapi".length));
+                       var deps_filename = "%s.deps".printf (filename.substring (0, filename.length - ".vapi".length));
                        if (!add_packages_from_file (deps_filename)) {
                                return false;
                        }
@@ -547,7 +547,7 @@ public class Vala.CodeContext {
        }
 
        private static bool ends_with_dir_separator (string s) {
-               return Path.is_dir_separator (s.offset (s.length - 1).get_char ());
+               return Path.is_dir_separator (s.get_char (s.length - 1));
        }
 
        /* ported from glibc */
@@ -569,10 +569,10 @@ public class Vala.CodeContext {
                        start = end = Path.skip_root (name);
 
                        // extract root
-                       rpath = name.substring (0, name.pointer_to_offset (start));
+                       rpath = name.substring (0, (int) ((char*) start - (char*) name));
                }
 
-               long root_len = rpath.pointer_to_offset (Path.skip_root (rpath));
+               long root_len = (long) ((char*) Path.skip_root (rpath) - (char*) rpath);
 
                for (; start.get_char () != 0; start = end) {
                        // skip sequence of multiple path-separators
index 51ba7c1db191dd5fcb9808a5b2172db12b3f0858..5d042043b16aa5801992a20313c4e840e80f5631 100644 (file)
@@ -182,12 +182,12 @@ public class Vala.Genie.Parser : CodeVisitor {
        }
        
        string get_current_string () {
-               return ((string) tokens[index].begin.pos).ndup ((tokens[index].end.pos - tokens[index].begin.pos));
+               return ((string) tokens[index].begin.pos).substring (0, (int) (tokens[index].end.pos - tokens[index].begin.pos));
        }
 
        string get_last_string () {
                int last_index = (index + BUFFER_SIZE - 1) % BUFFER_SIZE;
-               return ((string) tokens[last_index].begin.pos).ndup ((tokens[last_index].end.pos - tokens[last_index].begin.pos));
+               return ((string) tokens[last_index].begin.pos).substring (0, (int) (tokens[last_index].end.pos - tokens[last_index].begin.pos));
        }
 
        SourceReference get_src (SourceLocation begin) {
@@ -832,7 +832,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                                                        
                                                        if (len > 2) {
                                                                string s = "\\n\"";
-                                                               var st =  s_exp.value.ndup (len-1);
+                                                               var st =  s_exp.value.substring (0, len-1);
                                                                st += s;
                                                                s_exp.value = st;
                                                        }
index e1f945a285fecfff8ddf9f1d2dfa6767dafa0213..c853827632f8b6cda40ab72c132e23b426eb4c49 100644 (file)
@@ -1479,7 +1479,7 @@ public class Vala.Genie.Scanner {
                        }
                        
                        if (source_reference != null) {
-                               push_comment (((string) begin).ndup ((long) (current - begin)), source_reference, file_comment);
+                               push_comment (((string) begin).substring (0, (long) (current - begin)), source_reference, file_comment);
                        }
                        
                } else {
@@ -1511,7 +1511,7 @@ public class Vala.Genie.Scanner {
                        }
 
                        if (source_reference != null) {
-                               string comment = ((string) begin).ndup ((long) (current - begin));
+                               string comment = ((string) begin).substring (0, (long) (current - begin));
                                push_comment (comment, source_reference, file_comment);
                        }
 
@@ -1728,7 +1728,7 @@ public class Vala.Genie.Scanner {
                        return false;
                }
 
-               string identifier = ((string) (current - len)).ndup (len);
+               string identifier = ((string) (current - len)).substring (0, len);
                bool defined;
                if (identifier == "true") {
                        defined = true;
index b1b733c85a87dcdce374130ed3717ef4d90db52e..78afd729bd39f66ac58411f94ac046ee53d1139e 100644 (file)
@@ -280,7 +280,7 @@ public class Vala.GirParser : CodeVisitor {
                }
 
                string get_string () {
-                       return ((string) begin.pos).ndup ((end.pos - begin.pos));
+                       return ((string) begin.pos).substring (0, (int) (end.pos - begin.pos));
                }
 
                MetadataType? parse_metadata_access () {
@@ -575,7 +575,7 @@ public class Vala.GirParser : CodeVisitor {
                girdata_stack = new ArrayList<HashMap<string,string>> ();
 
                // load metadata
-               string metadata_filename = "%s.metadata".printf (source_file.filename.ndup (source_file.filename.length - ".gir".length));
+               string metadata_filename = "%s.metadata".printf (source_file.filename.substring (0, source_file.filename.length - ".gir".length));
                if (FileUtils.test (metadata_filename, FileTest.EXISTS)) {
                        var metadata_parser = new MetadataParser ();
                        var metadata_file = new SourceFile (context, source_file.file_type, metadata_filename);
@@ -1429,17 +1429,17 @@ public class Vala.GirParser : CodeVisitor {
                        common_prefix = cname;
                        while (common_prefix.length > 0 && !common_prefix.has_suffix ("_")) {
                                // FIXME: could easily be made faster
-                               common_prefix = common_prefix.ndup (common_prefix.length - 1);
+                               common_prefix = common_prefix.substring (0, common_prefix.length - 1);
                        }
                } else {
                        while (!cname.has_prefix (common_prefix)) {
-                               common_prefix = common_prefix.ndup (common_prefix.length - 1);
+                               common_prefix = common_prefix.substring (0, common_prefix.length - 1);
                        }
                }
                while (common_prefix.length > 0 && (!common_prefix.has_suffix ("_") ||
-                      (cname.offset (common_prefix.length).get_char ().isdigit ()) && (cname.length - common_prefix.length) <= 1)) {
+                      (cname.get_char (common_prefix.length).isdigit ()) && (cname.length - common_prefix.length) <= 1)) {
                        // enum values may not consist solely of digits
-                       common_prefix = common_prefix.ndup (common_prefix.length - 1);
+                       common_prefix = common_prefix.substring (0, common_prefix.length - 1);
                }
        }
 
@@ -2141,7 +2141,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_".length);
+                       m.name = m.name.substring ("new_".length);
                }
                if (cname != null) {
                        m.set_cname (cname);
@@ -2778,7 +2778,7 @@ public class Vala.GirParser : CodeVisitor {
                                        if (parent != null && (parent is Struct || parent is ObjectTypeSymbol || parent is Namespace)
                                                && cname.has_prefix (parent.get_lower_case_cprefix ())) {
                                                // instance method
-                                               var new_name = method.name.offset (parent.get_lower_case_cprefix().length-ns_cprefix.length);
+                                               var new_name = method.name.substring (parent.get_lower_case_cprefix().length - ns_cprefix.length);
                                                if (parent.scope.lookup (new_name) == null) {
                                                        method.name = new_name;
                                                        method.get_parameters().remove_at (0);
@@ -2794,7 +2794,7 @@ public class Vala.GirParser : CodeVisitor {
                                double match = 0;
                                Symbol parent = ns;
                                find_static_method_parent (cname, ns, ref parent, ref match, 1.0/cname.length);
-                               var new_name = method.name.offset (parent.get_lower_case_cprefix().length-ns_cprefix.length);
+                               var new_name = method.name.substring (parent.get_lower_case_cprefix().length - ns_cprefix.length);
                                if (parent.scope.lookup (new_name) == null) {
                                        method.name = new_name;
                                        add_symbol_to_container (parent, method);
index 4a5295b303fe753f28fd5b2abcc3b0aba6a8d670..1f85a21c5e6f954641483ef4ecf9e5dfb00326dd 100644 (file)
@@ -69,13 +69,13 @@ public class Vala.IntegerLiteral : Literal {
                int l = 0;
                while (value.has_suffix ("l") || value.has_suffix ("L")) {
                        l++;
-                       value = value.ndup (value.length - 1);
+                       value = value.substring (0, value.length - 1);
                }
 
                bool u = false;
                if (value.has_suffix ("u") || value.has_suffix ("U")) {
                        u = true;
-                       value = value.ndup (value.length - 1);
+                       value = value.substring (0, value.length - 1);
                }
                
                int64 n = value.to_int64 ();
index eef3f3fe1fbc1c3aff518bf4d346f9d05a5e1faa..72e0f64f71e89b2452f9383e788b56366a35e43d 100644 (file)
@@ -321,9 +321,9 @@ 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_".length);
+                       result = "type" + result.substring ("type_".length);
                } else if (result.has_prefix ("is_")) {
-                       result = "is" + result.offset ("is_".length);
+                       result = "is" + result.substring ("is_".length);
                }
                if (result.has_suffix ("_class")) {
                        result = result.substring (0, result.length - "_class".length) + "class";
index 843fba69ba8cce6e84549529d192183096ef2bca..9546faac1d0cf4be998d898f606fc3b0f29b10e9 100644 (file)
@@ -82,7 +82,7 @@ public class Vala.MarkupReader : Object {
                if (current == begin) {
                        // syntax error: invalid name
                }
-               return ((string) begin).ndup (current - begin);
+               return ((string) begin).substring (0, (int) (current - begin));
        }
 
        public MarkupTokenType read_token (out SourceLocation token_begin, out SourceLocation token_end) {
@@ -208,27 +208,27 @@ public class Vala.MarkupReader : Object {
                        } else if (u == '&') {
                                char* next_pos = current + u.to_utf8 (null);
                                if (((string) next_pos).has_prefix ("amp;")) {
-                                       content.append (((string) text_begin).ndup (current - text_begin));
+                                       content.append (((string) text_begin).substring (0, (int) (current - text_begin)));
                                        content.append_c ('&');
                                        current += 5;
                                        text_begin = current;
                                } else if (((string) next_pos).has_prefix ("quot;")) {
-                                       content.append (((string) text_begin).ndup (current - text_begin));
+                                       content.append (((string) text_begin).substring (0, (int) (current - text_begin)));
                                        content.append_c ('"');
                                        current += 6;
                                        text_begin = current;
                                } else if (((string) next_pos).has_prefix ("apos;")) {
-                                       content.append (((string) text_begin).ndup (current - text_begin));
+                                       content.append (((string) text_begin).substring (0, (int) (current - text_begin)));
                                        content.append_c ('\'');
                                        current += 6;
                                        text_begin = current;
                                } else if (((string) next_pos).has_prefix ("lt;")) {
-                                       content.append (((string) text_begin).ndup (current - text_begin));
+                                       content.append (((string) text_begin).substring (0, (int) (current - text_begin)));
                                        content.append_c ('<');
                                        current += 4;
                                        text_begin = current;
                                } else if (((string) next_pos).has_prefix ("gt;")) {
-                                       content.append (((string) text_begin).ndup (current - text_begin));
+                                       content.append (((string) text_begin).substring (0, (int) (current - text_begin)));
                                        content.append_c ('>');
                                        current += 4;
                                        text_begin = current;
@@ -248,7 +248,7 @@ public class Vala.MarkupReader : Object {
                }
 
                if (text_begin != current) {
-                       content.append (((string) text_begin).ndup (current - text_begin));
+                       content.append (((string) text_begin).substring (0, (int) (current - text_begin)));
                }
 
                column += (int) (current - last_linebreak);
index 65d062f5502907444cbd355ca7ec4e571799b3c2..8ef46b0336a0107b6a3bd9f3d4871bcceff8752a 100644 (file)
@@ -366,7 +366,7 @@ public class Vala.Method : Subroutine {
                        // avoid conflict with generated main function
                        return "_vala_main";
                } else if (name.has_prefix ("_")) {
-                       return "_%s%s".printf (parent_symbol.get_lower_case_cprefix (), name.offset (1));
+                       return "_%s%s".printf (parent_symbol.get_lower_case_cprefix (), name.substring (1));
                } else {
                        return "%s%s".printf (parent_symbol.get_lower_case_cprefix (), name);
                }
index 926654ebd3183334a01e2aafa21242439aac5055..b0626384cc8a431c38a2dd382f072dde32772a09 100644 (file)
@@ -136,12 +136,12 @@ public class Vala.Parser : CodeVisitor {
        }
 
        string get_current_string () {
-               return ((string) tokens[index].begin.pos).ndup ((tokens[index].end.pos - tokens[index].begin.pos));
+               return ((string) tokens[index].begin.pos).substring (0, (int) (tokens[index].end.pos - tokens[index].begin.pos));
        }
 
        string get_last_string () {
                int last_index = (index + BUFFER_SIZE - 1) % BUFFER_SIZE;
-               return ((string) tokens[last_index].begin.pos).ndup ((tokens[last_index].end.pos - tokens[last_index].begin.pos));
+               return ((string) tokens[last_index].begin.pos).substring (0, (int) (tokens[last_index].end.pos - tokens[last_index].begin.pos));
        }
 
        SourceReference get_src (SourceLocation begin) {
index 955b9a0944ce2d2abe311cac82801ce3b011507b..352ab686c6bafad5cc3d50d4182fe731a1861048 100644 (file)
@@ -1367,7 +1367,7 @@ public class Vala.Scanner {
                        return false;
                }
 
-               string identifier = ((string) (current - len)).ndup (len);
+               string identifier = ((string) (current - len)).substring (0, len);
                bool defined;
                if (identifier == "true") {
                        defined = true;
@@ -1512,7 +1512,7 @@ public class Vala.Scanner {
                        }
 
                        if (source_reference != null) {
-                               push_comment (((string) begin).ndup ((long) (current - begin)), source_reference, file_comment);
+                               push_comment (((string) begin).substring (0, (long) (current - begin)), source_reference, file_comment);
                        }
                } else {
                        SourceReference source_reference = null;
@@ -1544,7 +1544,7 @@ public class Vala.Scanner {
                        }
 
                        if (source_reference != null) {
-                               push_comment (((string) begin).ndup ((long) (current - begin)), source_reference, file_comment);
+                               push_comment (((string) begin).substring (0, (long) (current - begin)), source_reference, file_comment);
                        }
 
                        current += 2;
index 7891bc568e0564cb714bc1e2c67e1762cb5f6db1..6f8407f84077de1aff009e082abc3961fb3dae40 100644 (file)
@@ -486,7 +486,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                if (diag && prev_arg != null) {
                        var format_arg = prev_arg as StringLiteral;
                        if (format_arg != null) {
-                               format_arg.value = "\"%s:%d: %s".printf (Path.get_basename (expr.source_reference.file.filename), expr.source_reference.first_line, format_arg.value.offset (1));
+                               format_arg.value = "\"%s:%d: %s".printf (Path.get_basename (expr.source_reference.file.filename), expr.source_reference.first_line, format_arg.value.substring (1));
                        }
                }
 
index 931f02010385be5b2c9fb76bfb40c24df44fdd7e..8ab0e2f2f309427528c07fd5fb7be7376ca4a614 100644 (file)
@@ -178,7 +178,7 @@ public class Vala.SourceFile {
                        var basename = Path.get_basename (filename);
                        var subdir = filename.substring (context.basedir.length, filename.length - context.basedir.length - basename.length);
                        while (subdir[0] == '/') {
-                               subdir = subdir.offset (1);
+                               subdir = subdir.substring (1);
                        }
                        return subdir;
                }
@@ -193,7 +193,7 @@ public class Vala.SourceFile {
        }
 
        private string get_basename () {
-               long dot = filename.pointer_to_offset (filename.rchr (-1, '.'));
+               long dot = (long) ((char*) filename.rchr (-1, '.') - (char*) filename);
                return Path.get_basename (filename.substring (0, dot));
        }
 
index 5228e0e430d212224abf96e94a2525e8a0dc1177..e65f37a05243faa11504d7f0c5a998d743c625d8 100644 (file)
@@ -216,7 +216,7 @@ public abstract class Vala.Symbol : CodeNode {
                }
 
                string parent_gir_name = parent_symbol.get_full_gir_name ();
-               string self_gir_name = gir_name.has_prefix (".") ? gir_name.offset (1) : gir_name;
+               string self_gir_name = gir_name.has_prefix (".") ? gir_name.substring (1) : gir_name;
                if (parent_gir_name.str (".") != null) {
                        return "%s%s".printf (parent_gir_name, self_gir_name);
                } else {
@@ -349,7 +349,7 @@ public abstract class Vala.Symbol : CodeNode {
                                        /* previous character wasn't upper case or
                                         * next character isn't upper case*/
                                        long len = result_builder.str.length;
-                                       if (len != 1 && result_builder.str.offset (len - 2).get_char () != '_') {
+                                       if (len != 1 && result_builder.str.get_char (len - 2) != '_') {
                                                /* we're not creating 1 character words */
                                                result_builder.append_c ('_');
                                        }
index c3abf8b38b81ca109e176ae679dfca7e7076295f..5643c2d247d6017dc80606434ea5829df7684bc3 100644 (file)
@@ -1007,19 +1007,31 @@ public class string {
        public unowned string next_char ();
        [CCode (cname = "g_utf8_get_char")]
        static unichar utf8_get_char (char* str);
-       public unichar get_char (int index = 0) {
+       public unichar get_char (long index = 0) {
                return utf8_get_char ((char*) this + index);
        }
        [CCode (cname = "g_utf8_get_char_validated")]
        public unichar get_char_validated (ssize_t max_len = -1);
+
+       [Deprecated (replacement = "string.index_of_nth_char")]
        [CCode (cname = "g_utf8_offset_to_pointer")]
        public unowned string utf8_offset (long offset);
+       [Deprecated (replacement = "string.substring")]
        public unowned string offset (long offset) {
                return (string) ((char*) this + offset);
        }
+       [Deprecated (replacement = "string.char_count")]
        public long pointer_to_offset (string pos) {
                return (long) ((char*) pos - (char*) this);
        }
+
+       [CCode (cname = "g_utf8_offset_to_pointer")]
+       char* utf8_offset_to_pointer (long offset);
+
+       public int index_of_nth_char (long c) {
+               return (int) (this.utf8_offset_to_pointer (c) - (char*) this);
+       }
+
        [CCode (cname = "g_utf8_prev_char")]
        public unowned string prev_char ();
        [Deprecated (replacement = "string.length")]
@@ -1126,9 +1138,13 @@ public class string {
 
        [CCode (cname = "g_strdup")]
        public string dup ();
+       [Deprecated (replacement = "string.substring")]
        [CCode (cname = "g_strndup")]
        public string ndup (size_t n);
 
+       [CCode (cname = "g_strndup")]
+       static string strndup (char* str, size_t n);
+
        public string substring (long offset, long len = -1) {
                long string_length = this.length;
                if (offset < 0) {
@@ -1141,8 +1157,7 @@ public class string {
                        len = string_length - offset;
                }
                GLib.return_val_if_fail (offset + len <= string_length, null);
-               unowned string start = this.offset (offset);
-               return start.ndup (((char*) start.offset (len)) - ((char*) start));
+               return strndup ((char*) this + offset, len);
        }
 
        public string slice (long start, long end) {
@@ -1156,8 +1171,7 @@ public class string {
                GLib.return_val_if_fail (start >= 0 && start <= string_length, null);
                GLib.return_val_if_fail (end >= 0 && end <= string_length, null);
                GLib.return_val_if_fail (start <= end, null);
-               unowned string start_string = this.offset (start);
-               return start_string.ndup (((char*) start_string.offset (end - start)) - ((char*) start_string));
+               return strndup ((char*) this + start, end - start);
        }
 
        public string splice (long start, long end, string? str = null) {
@@ -1172,8 +1186,6 @@ public class string {
                GLib.return_val_if_fail (end >= 0 && end <= string_length, null);
                GLib.return_val_if_fail (start <= end, null);
 
-               unowned string start_string = this.offset (start);
-               unowned string end_string = start_string.offset (end - start);
                size_t str_size;
                if (str == null) {
                        str_size = 0;
@@ -1181,17 +1193,17 @@ public class string {
                        str_size = str.length;
                }
 
-               string* result = GLib.malloc0 (this.length - ((char*) end_string - (char*) start_string) + str_size + 1);
+               string* result = GLib.malloc0 (this.length - (end - start) + str_size + 1);
 
                char* dest = (char*) result;
 
-               GLib.Memory.copy (dest, this, (char*) start_string - (char*) this);
-               dest += (char*) start_string - (char*) this;
+               GLib.Memory.copy (dest, this, start);
+               dest += start;
 
                GLib.Memory.copy (dest, str, str_size);
                dest += str_size;
 
-               GLib.Memory.copy (dest, end_string, end_string.length);
+               GLib.Memory.copy (dest, (char*) this + end, string_length - end);
 
                return (owned) result;
        }
index 46d0747e96102fc40c4f0063c106e2efaa60fb2f..ccc6e4f6c5c539505dab9cf4cc69c5f8ebdff702 100644 (file)
@@ -100,7 +100,7 @@ public class Vala.GIdlParser : CodeVisitor {
        }
        
        private void parse_file (SourceFile source_file) {
-               string metadata_filename = "%s.metadata".printf (source_file.filename.ndup (source_file.filename.length - ".gi".length));
+               string metadata_filename = "%s.metadata".printf (source_file.filename.substring (0, source_file.filename.length - ".gi".length));
 
                current_source_file = source_file;
 
@@ -164,9 +164,9 @@ public class Vala.GIdlParser : CodeVisitor {
                }
 
                if (type_name.has_prefix (container.name)) {
-                       return type_name.offset (container.name.length);
+                       return type_name.substring (container.name.length);
                } else if (container.name == "GLib" && type_name.has_prefix ("G")) {
-                       return type_name.offset (1);
+                       return type_name.substring (1);
                } else  {
                        string best_match = null;
                        if (container is Namespace) {
@@ -181,7 +181,7 @@ public class Vala.GIdlParser : CodeVisitor {
                }
 
                        if (best_match != null) {
-                               return type_name.offset (best_match.length);;
+                               return type_name.substring (best_match.length);;
                        }
                }
 
@@ -191,7 +191,7 @@ public class Vala.GIdlParser : CodeVisitor {
        private string fix_const_name (string const_name, Symbol container) {
                var pref = container.get_lower_case_cprefix ().up ();
                if (const_name.has_prefix (pref)) {
-                       return const_name.offset (pref.length);
+                       return const_name.substring (pref.length);
                }
                return const_name;
        }
@@ -1167,17 +1167,17 @@ public class Vala.GIdlParser : CodeVisitor {
                                common_prefix = value.name;
                                while (common_prefix.length > 0 && !common_prefix.has_suffix ("_")) {
                                        // FIXME: could easily be made faster
-                                       common_prefix = common_prefix.ndup (common_prefix.length - 1);
+                                       common_prefix = common_prefix.substring (0, common_prefix.length - 1);
                                }
                        } else {
                                while (!value.name.has_prefix (common_prefix)) {
-                                       common_prefix = common_prefix.ndup (common_prefix.length - 1);
+                                       common_prefix = common_prefix.substring (0, common_prefix.length - 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)) {
+                              (value.name.get_char (common_prefix.length).isdigit ()) && (value.name.length - common_prefix.length) <= 1)) {
                                // enum values may not consist solely of digits
-                               common_prefix = common_prefix.ndup (common_prefix.length - 1);
+                               common_prefix = common_prefix.substring (0, common_prefix.length - 1);
                        }
                }
 
@@ -1239,7 +1239,7 @@ public class Vala.GIdlParser : CodeVisitor {
                        }
 
                        if (!is_hidden) {
-                               var ev = new EnumValue (value2.name.offset (common_prefix.length), null);
+                               var ev = new EnumValue (value2.name.substring (common_prefix.length), null);
                                en.add_value (ev);
                        }
                }
@@ -1638,7 +1638,7 @@ public class Vala.GIdlParser : CodeVisitor {
                        }
                        
                        if (n.has_prefix ("const-")) {
-                               n = n.offset ("const-".length);
+                               n = n.substring ("const-".length);
                        }
 
                        if (type_node.is_pointer &&
@@ -1749,7 +1749,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]).length));
+                                       type.unresolved_symbol = new UnresolvedSymbol (null, n.substring (eval (nv[1]).length));
                                } else if (nv[0] == "name") {
                                        type.unresolved_symbol = new UnresolvedSymbol (null, eval (nv[1]));
                                } else if (nv[0] == "namespace") {
@@ -1771,9 +1771,9 @@ 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.length));
+                       type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, current_namespace.name), n.substring (current_namespace.name.length));
                } else if (n.has_prefix ("G")) {
-                       type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, "GLib"), n.offset (1));
+                       type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, "GLib"), n.substring (1));
                } else {
                        var name_parts = n.split (".", 2);
                        if (name_parts[1] == null) {
@@ -1941,7 +1941,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_".length);
+                               m.name = m.name.substring ("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
@@ -2064,7 +2064,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                        var prefix = container.get_lower_case_cprefix ();
                                        if (symbol.has_prefix (prefix)) {
                                                m.set_cname (m.name);
-                                               m.name = symbol.offset (prefix.length);
+                                               m.name = symbol.substring (prefix.length);
                                        }
                                }
                        }
@@ -2228,7 +2228,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.length);
+                                                       char* val_end = (char*) val + val.length;
 
                                                        val.to_long (out endptr);
                                                        if ((long)endptr == (long)val_end) {
@@ -2668,7 +2668,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                }
                        }
 
-                       remaining = remaining.offset (1);
+                       remaining = (string) ((char*) remaining + remaining.index_of_nth_char (1));
                }
 
                if (attr.len > 0) {
@@ -2685,7 +2685,7 @@ public class Vala.GIdlParser : CodeVisitor {
        }
        
        private string eval (string s) {
-               return ((s.length >= 2) && s.has_prefix ("\"") && s.has_suffix ("\"")) ? s.offset (1).ndup (s.length - 2) : s;
+               return ((s.length >= 2) && s.has_prefix ("\"") && s.has_suffix ("\"")) ? s.substring (1, s.length - 2) : s;
        }
 
        private Signal? parse_signal (IdlNodeSignal sig_node) {
index 2968b0ae127ca5ec552b8b8bfeb7f5111a254824..5345b63b359a4d468f876917c1b3770b3c63255c 100644 (file)
@@ -166,7 +166,7 @@ class Vala.VAPIGen : Object {
                        if (file.filename in sources) {
                                file.file_type = SourceFileType.SOURCE;
                        } else if (file.filename.has_suffix (".metadata")) {
-                               string gir_filename = "%s.gir".printf (file.filename.ndup (file.filename.length - ".metadata".length));
+                               string gir_filename = "%s.gir".printf (file.filename.substring (0, file.filename.length - ".metadata".length));
                                if (gir_filename in sources) {
                                        file.file_type = SourceFileType.SOURCE;
                                }