core: Correctly compare strings
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Mon, 26 Jul 2010 18:33:01 +0000 (21:33 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Mon, 2 Aug 2010 15:55:48 +0000 (18:55 +0300)
We need to be using string.collatate() rather than GLib.strcmp as the
former does a locale-sensitive comparison of UTF-8 strings.

src/rygel/rygel-media-object.vala

index 1039781..6b3a01e 100644 (file)
@@ -99,15 +99,27 @@ public abstract class Rygel.MediaObject : GLib.Object {
                                               string      property) {
         switch (property) {
         case "@id":
-            return strcmp (this.id, media_object.id);
+            return this.compare_string_props (this.id, media_object.id);
         case "@parentID":
-            return strcmp (this.parent, media_object.parent);
+            return this.compare_string_props (this.parent.id,
+                                              media_object.parent.id);
         case "dc:title":
-            return strcmp (this.title, media_object.title);
+            return this.compare_string_props (this.title, media_object.title);
         case "upnp:class":
-            return strcmp (this.upnp_class, media_object.upnp_class);
+            return this.compare_string_props (this.upnp_class,
+                                              media_object.upnp_class);
         default:
             return 0;
         }
     }
+
+    protected int compare_string_props (string prop1, string prop2) {
+        if (prop1 == null) {
+            return -1;
+        } else if (prop2 == null) {
+            return 1;
+        } else {
+            return prop1.collate (prop2);
+        }
+    }
 }