[glib/wip/gsettingsbackendchangeset: 2/5] GSettingsBackend: add path checking helpers
- From: Allison Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gsettingsbackendchangeset: 2/5] GSettingsBackend: add path checking helpers
- Date: Wed, 3 Feb 2016 11:09:42 +0000 (UTC)
commit 059fb995b1bb76b41b942a432aac6237927dc6f0
Author: Allison Ryan Lortie <desrt desrt ca>
Date: Wed Jan 13 12:20:17 2016 -0500
GSettingsBackend: add path checking helpers
Add helpers for checking if a string is a valid GSettingsBackend
[path|key|dir].
These helpers match equivalent functions found in dconf and will be used
for assertion checking when adding GSettingsBackendChangeset.
docs/reference/gio/gio-sections.txt | 3 +
gio/gsettingsbackend.c | 87 +++++++++++++++++++++++++++++++++++
gio/gsettingsbackend.h | 7 +++
3 files changed, 97 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index 9eb68b2..8be86c6 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -2497,6 +2497,9 @@ G_TYPE_FILE_DESCRIPTOR_BASED
GSettingsBackend
GSettingsBackendClass
G_SETTINGS_BACKEND_EXTENSION_POINT_NAME
+g_settings_backend_is_path
+g_settings_backend_is_key
+g_settings_backend_is_dir
g_settings_backend_get_default
g_settings_backend_changed
g_settings_backend_path_changed
diff --git a/gio/gsettingsbackend.c b/gio/gsettingsbackend.c
index f211e2c..cf14fb3 100644
--- a/gio/gsettingsbackend.c
+++ b/gio/gsettingsbackend.c
@@ -1044,3 +1044,90 @@ g_settings_backend_sync_default (void)
class->sync (backend);
}
}
+
+/**
+ * g_settings_backend_is_path:
+ * @string: a string
+ *
+ * Checks if @string is a valid #GSettingsBackend path. Paths must
+ * start with '/' and not contain '//'.
+ *
+ * A path may be either a key or a dir. See g_settings_backend_is_key()
+ * and g_settings_backend_is_dir() for examples of each.
+ *
+ * Returns: %TRUE if @string is a path
+ **/
+gboolean
+g_settings_backend_is_path (const gchar *string)
+{
+ if (string[0] != '/')
+ return FALSE;
+
+ if (strstr (string, "//"))
+ return FALSE;
+
+ return TRUE;
+}
+
+/**
+ * g_settings_backend_is_key:
+ * @string: a string
+ *
+ * Checks if @string is a valid #GSettingsBackend key. Keys must
+ * start with '/', not contain '//' and not end with '/'.
+ *
+ * A key is the potential location of a single value within a
+ * #GSettingsBackend.
+ *
+ * "/a", "/a/b" and "/a/b/c" are examples of keys. "", "/", "a", "a/b",
+ * "//a/b", "/a//b", and "/a/" are examples of strings that are not
+ * keys.
+ *
+ * Returns: %TRUE if @string is a key
+ **/
+gboolean
+g_settings_backend_is_key (const gchar *string)
+{
+ if (string[0] != '/')
+ return FALSE;
+
+ if (strstr (string, "//"))
+ return FALSE;
+
+ if (g_str_has_suffix (string, "/"))
+ return FALSE;
+
+ return TRUE;
+}
+
+/**
+ * g_settings_backend_is_dir:
+ * @string: a string
+ *
+ * Checks if @string is a valid #GSettingsBackend dir. dirs must start
+ * and end with '/' and not contain '//'.
+ *
+ * A dir refers to a subtree of the database that can contain other dirs
+ * or keys. If @string is a dir, then it will be a prefix of any key or
+ * dir contained within it.
+ *
+ * "/", "/a/" and "/a/b/" are examples of dirs. "", "a/", "a/b/",
+ * "//a/b/", "/a//b/" and "/a" are examples of strings that are not
+ * dirs.
+ *
+ * Returns: %TRUE if @string is a dir
+ **/
+gboolean
+g_settings_backend_is_dir (const gchar *string)
+{
+ if (string[0] != '/')
+ return FALSE;
+
+ if (strstr (string, "//"))
+ return FALSE;
+
+ if (!g_str_has_suffix (string, "/"))
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/gio/gsettingsbackend.h b/gio/gsettingsbackend.h
index 86e0431..499b2d4 100644
--- a/gio/gsettingsbackend.h
+++ b/gio/gsettingsbackend.h
@@ -169,6 +169,13 @@ GSettingsBackend * g_null_settings_backend_new (void);
GLIB_AVAILABLE_IN_ALL
GSettingsBackend * g_memory_settings_backend_new (void);
+GLIB_AVAILABLE_IN_2_48
+gboolean g_settings_backend_is_path (const gchar *string);
+GLIB_AVAILABLE_IN_2_48
+gboolean g_settings_backend_is_key (const gchar *string);
+GLIB_AVAILABLE_IN_2_48
+gboolean g_settings_backend_is_dir (const gchar *string);
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSettingsBackend, g_object_unref)
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]