]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
GIR writer: Remove GLib.Regex reference
authorMark Lee <marklee@src.gnome.org>
Thu, 28 May 2009 08:43:40 +0000 (01:43 -0700)
committerJürg Billeter <j@bitron.ch>
Thu, 28 May 2009 18:41:32 +0000 (20:41 +0200)
The GRegex reference prevents compilation with GLib 2.12. The code has
been replaced with equivalent code derived from the string class.

Fixes bug 584098.

compiler/valacompiler.vala

index 2bb6c00d31bada810c191a269e62f529b6397b05..06c8bf6d38b36329740d10e4a122947b5eebac33 100644 (file)
@@ -363,22 +363,29 @@ class Vala.Compiler {
                if (library != null) {
                        if (gir != null) {
                                if (context.profile == Profile.GOBJECT) {
-                                       string[] split_gir = Regex.split_simple("(.*)-([0-9]+(\\.[0-9]+)?)\\.gir$", gir);
+                                       long gir_len = gir.len ();
+                                       unowned string? last_hyphen = gir.rchr (gir_len, '-');
 
-                                       if (split_gir.length < 4) {
+                                       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 {
-                                               var gir_writer = new GIRWriter ();
-                                               string gir_namespace = split_gir[1];
-                                               string gir_version = split_gir[2];
-
-                                               // put .gir file in current directory unless -d has been explicitly specified
-                                               string gir_directory = ".";
-                                               if (directory != null) {
-                                                       gir_directory = context.directory;
+                                               long offset = gir.pointer_to_offset (last_hyphen);
+                                               string gir_namespace = gir.substring (0, offset);
+                                               string gir_version = gir.substring (offset + 1, gir_len - offset - 5);
+                                               gir_version.canon ("0123456789.", '?');
+                                               if (gir_namespace == "" || gir_version == "" || !gir_version[0].isdigit () || gir_version.contains ("?")) {
+                                                       Report.error (null, "GIR file name `%s' is not well-formed, expected NAME-VERSION.gir".printf (gir));
+                                               } else {
+                                                       var gir_writer = new GIRWriter ();
+
+                                                       // put .gir file in current directory unless -d has been explicitly specified
+                                                       string gir_directory = ".";
+                                                       if (directory != null) {
+                                                               gir_directory = context.directory;
+                                                       }
+
+                                                       gir_writer.write_file (context, gir_directory, gir_namespace, gir_version, library);
                                                }
-
-                                               gir_writer.write_file (context, gir_directory, gir_namespace, gir_version, library);
                                        }
                                }