diff options
author | Corentin Noël <corentin@elementary.io> | 2019-10-04 13:52:58 +0000 |
---|---|---|
committer | Alberto Fanjul <albertofanjul@gmail.com> | 2019-10-04 13:52:58 +0000 |
commit | ddcb64d2e5a7698688c71881db40a3cc317102ed (patch) | |
tree | 4aad8d83dfcf5aff584bd15a26dfc82808bbcefa | |
parent | 7e202648640b7a926645b97e9314f3a1b53ddabe (diff) | |
download | glade-ddcb64d2e5a7698688c71881db40a3cc317102ed.tar.gz |
gladeui: Change the boolean parsing logic to be the same as Gtk
Avoids false positive
-rw-r--r-- | gladeui/glade-utils.c | 78 |
1 files changed, 50 insertions, 28 deletions
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c index 82bd34c2..c0fd07d0 100644 --- a/gladeui/glade-utils.c +++ b/gladeui/glade-utils.c @@ -1585,49 +1585,71 @@ glade_utils_value_from_string (GType type, /** * glade_utils_boolean_from_string: * @string: the string to convert - * @value: return location + * @value: (out) (optional): return location * * Parse a boolean value * - * Returns: True if there was an error on the conversion. + * Returns: %TRUE if there was an error on the conversion, %FALSE otherwise. */ gboolean glade_utils_boolean_from_string (const gchar *string, gboolean *value) { - if (string) + if (string[0] == '\0') { - const gchar *c = string; + if (value) + *value = FALSE; - /* Skip white spaces */ - while (g_ascii_isspace (*c)) - c++; + return TRUE; + } + else if (string[1] == '\0') + { + gchar c = string[0]; + if (c == '1' || + c == 'y' || c == 't' || + c == 'Y' || c == 'T') + { + if (value) + *value = TRUE; + } + else if (c == '0' || + c == 'n' || c == 'f' || + c == 'N' || c == 'F') + { + if (value) + *value = FALSE; + } + else + { + if (value) + *value = FALSE; - /* We only need the first char */ - switch (*c) + return TRUE; + } + } + else + { + if (g_ascii_strcasecmp (string, "true") == 0 || + g_ascii_strcasecmp (string, "yes") == 0) { - case '1': - case 't': - case 'T': - case 'y': - case 'Y': - if (value) - *value = TRUE; - return FALSE; - break; + if (value) + *value = TRUE; + } + else if (g_ascii_strcasecmp (string, "false") == 0 || + g_ascii_strcasecmp (string, "no") == 0) + { + if (value) + *value = FALSE; + } + else + { + if (value) + *value = FALSE; - case '0': - case 'f': - case 'F': - case 'n': - case 'N': - if (value) - *value = FALSE; - return FALSE; - break; + return TRUE; } } - return TRUE; + return FALSE; } /** |