summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-11-29 20:17:16 -0500
committerRyan Lortie <desrt@desrt.ca>2013-12-01 23:38:09 -0500
commita552bb0659aea9703b2d3851b784e2e1e6c9a9d8 (patch)
tree0fc04775f2dca6a5c1b5e5ebd593ba53d0f84bc1
parenta3adaeac5b025fb131868982a1b6ed1dd3f08def (diff)
downloaddconf-a552bb0659aea9703b2d3851b784e2e1e6c9a9d8.tar.gz
new api: dconf_match()
-rw-r--r--client/dconf.vapi2
-rw-r--r--common/dconf-paths.c35
-rw-r--r--common/dconf-paths.h2
-rw-r--r--docs/dconf-sections.txt2
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>