[gnome-boxes] util: copy a few helpers from gnome-contacts



commit 2a46acc955410c3acdec488798d8dc7854f40659
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Mon Aug 13 12:04:25 2012 +0300

    util: copy a few helpers from gnome-contacts
    
    https://bugzilla.gnome.org/show_bug.cgi?id=681246

 src/util.vala |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/src/util.vala b/src/util.vala
index 3b09c16..98576a6 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -267,6 +267,10 @@ namespace Boxes {
         }
     }
 
+    public bool is_set (string? str) {
+        return str != null && str != "";
+    }
+
     public string yes_no (bool value) {
         return value ? N_("yes") : N_("no");
     }
@@ -285,6 +289,38 @@ namespace Boxes {
         return indented;
     }
 
+    // shamelessly copied form gnome-contacts
+    private static unichar strip_char (unichar ch) {
+        switch (ch.type ()) {
+        case UnicodeType.CONTROL:
+        case UnicodeType.FORMAT:
+        case UnicodeType.UNASSIGNED:
+        case UnicodeType.NON_SPACING_MARK:
+        case UnicodeType.COMBINING_MARK:
+        case UnicodeType.ENCLOSING_MARK:
+            /* Ignore those */
+            return 0;
+        default:
+            return ch.tolower ();
+        }
+    }
+
+    // shamelessly copied form gnome-contacts
+    public static string canonicalize_for_search (string str) {
+        unowned string s;
+        var buf = new unichar[18];
+        var res = new StringBuilder ();
+        for (s = str; s[0] != 0; s = s.next_char ()) {
+            var c = strip_char (s.get_char ());
+            if (c != 0) {
+                var size = c.fully_decompose (false, buf);
+                if (size > 0)
+                    res.append_unichar (buf[0]);
+            }
+        }
+        return res.str;
+    }
+
     [DBus (name = "org.freedesktop.Accounts")]
     interface Fdo.Accounts : Object {
         public abstract async string FindUserByName(string name) throws IOError;



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