[dconf] add "relative key" check



commit 837d41503d0bff595b6275ef12cad6057ae53f3a
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Oct 7 15:08:21 2009 -0400

    add "relative key" check

 dconf/dconf.c |   32 ++++++++++++++++++++++++++++++++
 dconf/dconf.h |    1 +
 2 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/dconf/dconf.c b/dconf/dconf.c
index 683d2a3..dd934eb 100644
--- a/dconf/dconf.c
+++ b/dconf/dconf.c
@@ -112,6 +112,38 @@ dconf_is_key_or_path (const gchar *key_or_path)
 }
 
 /**
+ * dconf_is_relative_key:
+ * @relative_key: a possible relative key
+ * @Returns: %TRUE if @relative_key is valid
+ *
+ * Determines if @relative_key is a valid relative key.
+ *
+ * A relative key is valid if it does not start with a slash, does not
+ * end with a slash, and contains no two consecutive slashes.  The empty
+ * string is not a valid relative key.
+ *
+ * Another definition is that a relative key is any string that may be
+ * appended to a valid path to form a valid key.
+ **/
+gboolean
+dconf_is_relative_key (const char *relative_key)
+{
+  int i;
+
+  if (relative_key == NULL)
+    return FALSE;
+
+  if (relative_key[0] == '/')
+    return FALSE;
+
+  for (i = 0; relative_key[i]; i++)
+    if (relative_key[i] == '/' && relative_key[i + 1] == '/')
+      return FALSE;
+
+  return relative_key[i - 1] != '/';
+}
+
+/**
  * dconf_match:
  * @key_or_path1: a dconf key or path
  * @key_or_path2: a dconf key or path
diff --git a/dconf/dconf.h b/dconf/dconf.h
index d3a059e..a3020da 100644
--- a/dconf/dconf.h
+++ b/dconf/dconf.h
@@ -27,6 +27,7 @@ typedef void          (*DConfWatchFunc)                                 (const g
 gboolean                dconf_is_key                                    (const gchar              *key);
 gboolean                dconf_is_path                                   (const gchar              *path);
 gboolean                dconf_is_key_or_path                            (const gchar              *key_or_path);
+gboolean                dconf_is_relative_key                           (const gchar              *relative_key);
 gboolean                dconf_match                                     (const gchar              *key_or_path1,
                                                                          const gchar              *key_or_path2);
 



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