[dconf/wip/varlib: 5/12] new api: dconf_match()



commit a552bb0659aea9703b2d3851b784e2e1e6c9a9d8
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Nov 29 20:17:16 2013 -0500

    new api: dconf_match()

 client/dconf.vapi       |    2 ++
 common/dconf-paths.c    |   35 +++++++++++++++++++++++++++++++++++
 common/dconf-paths.h    |    2 ++
 docs/dconf-sections.txt |    2 ++
 4 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/client/dconf.vapi b/client/dconf.vapi
index eadc121..aa26b7d 100644
--- a/client/dconf.vapi
+++ b/client/dconf.vapi
@@ -59,4 +59,6 @@ namespace DConf {
        public static bool verify_rel_key (string str) throws GLib.Error;
        [CCode (cheader_filename = "dconf.h", cname = "dconf_is_rel_path")]
        public static bool verify_rel_path (string str) throws GLib.Error;
+       [CCode (cheader_filename = "dconf.h")]
+       public static bool match (string path_a, string path_b);
 }
diff --git a/common/dconf-paths.c b/common/dconf-paths.c
index 467f525..8968d05 100644
--- a/common/dconf-paths.c
+++ b/common/dconf-paths.c
@@ -26,6 +26,8 @@
 
 #include "dconf-error.h"
 
+#include <string.h>
+
 /**
  * SECTION:paths
  * @title: dconf Paths
@@ -253,3 +255,36 @@ dconf_is_rel_dir (const gchar  *string,
   vars; nonnull; relative; no_double_slash; dir;
 #undef type
 }
+
+/**
+ * dconf_match:
+ * @path_a: a dconf path
+ * @path_b: a dconf path
+ *
+ * Compare two paths using the (symmetric) dconf "match" operation.
+ *
+ * Two paths match if either they are exactly equal or if one of them
+ * (ending with '/') is a prefix of the other.
+ *
+ * The result if this function is undefined if either of the two
+ * arguments are not dconf paths.
+ *
+ * Returns: %TRUE if the paths match
+ **/
+gboolean
+dconf_match (const gchar *path_a,
+             const gchar *path_b)
+{
+  int len_a, len_b;
+
+  len_a = strlen (path_a);
+  len_b = strlen (path_b);
+
+  if (len_a < len_b && path_a[len_a - 1] != '/')
+    return FALSE;
+
+  if (len_b < len_a && path_b[len_b -1] != '/')
+    return FALSE;
+
+  return memcmp (path_a, path_b, MIN (len_a, len_b)) == 0;
+}
diff --git a/common/dconf-paths.h b/common/dconf-paths.h
index 75e9add..7af652d 100644
--- a/common/dconf-paths.h
+++ b/common/dconf-paths.h
@@ -38,5 +38,7 @@ gboolean                dconf_is_rel_key                                (const g
                                                                          GError             **error);
 gboolean                dconf_is_rel_dir                                (const gchar         *string,
                                                                          GError             **error);
+gboolean                dconf_match                                     (const gchar         *path_a,
+                                                                         const gchar         *path_b);
 
 #endif /* __dconf_paths_h__ */
diff --git a/docs/dconf-sections.txt b/docs/dconf-sections.txt
index e6ad847..bd60b61 100644
--- a/docs/dconf-sections.txt
+++ b/docs/dconf-sections.txt
@@ -38,6 +38,8 @@ dconf_is_path
 dconf_is_rel_path
 dconf_is_rel_dir
 dconf_is_rel_key
+<SUBSECTION>
+dconf_match
 </SECTION>
 
 <SECTION>


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