[rygel] core: Correctly compare strings



commit 57ce3afba7d553ff9ac3e33db25267948b365f1d
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Jul 26 21:33:01 2010 +0300

    core: Correctly compare strings
    
    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 |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
---
diff --git a/src/rygel/rygel-media-object.vala b/src/rygel/rygel-media-object.vala
index 1039781..6b3a01e 100644
--- a/src/rygel/rygel-media-object.vala
+++ b/src/rygel/rygel-media-object.vala
@@ -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);
+        }
+    }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]