summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Pablo Ugarte <juanpablougarte@gmail.com>2017-11-18 12:01:12 -0300
committerJuan Pablo Ugarte <juanpablougarte@gmail.com>2017-11-18 12:08:51 -0300
commitd2045f1f8977d9d3dbdbc674a7f5ab6e6d82c167 (patch)
tree6a74457855bb31a0dd3e6ffa9a52289fd9dc0484
parent16c7d3373d4ec3a479672ba4637c43c989287329 (diff)
downloadglade-d2045f1f8977d9d3dbdbc674a7f5ab6e6d82c167.tar.gz
Add glade_utils_boolean_from_string() to the zoo
-rw-r--r--gladeui/glade-utils.c47
-rw-r--r--gladeui/glade-utils.h2
2 files changed, 49 insertions, 0 deletions
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index 6fbc5d2d..d5f3671a 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -1587,6 +1587,53 @@ glade_utils_value_from_string (GType type,
return NULL;
}
+/**
+ * glade_utils_boolean_from_string:
+ * @string: the string to convert
+ * @value: return location
+ *
+ * Parse a boolean value
+ *
+ * Returns: True if there was an error on the conversion.
+ */
+gboolean
+glade_utils_boolean_from_string (const gchar *string, gboolean *value)
+{
+ if (string)
+ {
+ const gchar *c = string;
+
+ /* Skip white spaces */
+ while (g_ascii_isspace (*c))
+ c++;
+
+ /* We only need the first char */
+ switch (*c)
+ {
+ case '1':
+ case 't':
+ case 'T':
+ case 'y':
+ case 'Y':
+ if (value)
+ *value = TRUE;
+ return FALSE;
+ break;
+
+ case '0':
+ case 'f':
+ case 'F':
+ case 'n':
+ case 'N':
+ if (value)
+ *value = FALSE;
+ return FALSE;
+ break;
+ }
+ }
+
+ return TRUE;
+}
/**
* glade_utils_string_from_value:
diff --git a/gladeui/glade-utils.h b/gladeui/glade-utils.h
index ca02a5ba..c074b5fb 100644
--- a/gladeui/glade-utils.h
+++ b/gladeui/glade-utils.h
@@ -67,6 +67,8 @@ GValue *glade_utils_value_from_string (GType type,
const gchar *string,
GladeProject *project);
gchar *glade_utils_string_from_value (const GValue *value);
+gboolean glade_utils_boolean_from_string (const gchar *string,
+ gboolean *value);
/* Devhelp */
gboolean glade_util_have_devhelp (void);