[gtk/matthiasc/a11y-buildable: 4/6] a11y: Reuse builder parsing for enums
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/a11y-buildable: 4/6] a11y: Reuse builder parsing for enums
- Date: Sun, 25 Oct 2020 17:03:14 +0000 (UTC)
commit 677ea5f22d63d514dffe51db552f3d1ea311d0e3
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Oct 25 12:38:52 2020 -0400
a11y: Reuse builder parsing for enums
No need to manually write all these parsing functions
when _gtk_builder_enum_from_string does exactly what
is needed here.
gtk/gtkaccessiblevaluestatic.c | 67 ++++++++++++------------------------------
1 file changed, 19 insertions(+), 48 deletions(-)
---
diff --git a/gtk/gtkaccessiblevaluestatic.c b/gtk/gtkaccessiblevaluestatic.c
index 5cb761eba5..c506103453 100644
--- a/gtk/gtkaccessiblevaluestatic.c
+++ b/gtk/gtkaccessiblevaluestatic.c
@@ -21,6 +21,9 @@
#include "config.h"
#include "gtkaccessiblevalueprivate.h"
+#include "gtkbuilderprivate.h"
+#include "gtkenums.h"
+#include "gtktypebuiltins.h"
/* {{{ Undefined value */
@@ -287,21 +290,12 @@ gtk_invalid_accessible_value_parse (const char *str,
gsize len,
GError **error)
{
+ int value;
+
g_return_val_if_fail (str == NULL || len == 0, NULL);
- if (strncmp (str, "false", 5) == 0)
- return gtk_invalid_accessible_value_new (GTK_ACCESSIBLE_INVALID_FALSE);
- else if (strncmp (str, "true", 4) == 0)
- return gtk_invalid_accessible_value_new (GTK_ACCESSIBLE_INVALID_TRUE);
- else if (strncmp (str, "grammar", 7) == 0)
- return gtk_invalid_accessible_value_new (GTK_ACCESSIBLE_INVALID_GRAMMAR);
- else if (strncmp (str, "spelling", 8) == 0)
- return gtk_invalid_accessible_value_new (GTK_ACCESSIBLE_INVALID_SPELLING);
- else
- g_set_error (error, GTK_ACCESSIBLE_VALUE_ERROR,
- GTK_ACCESSIBLE_VALUE_ERROR_INVALID_TOKEN,
- "Unknown token “%s”",
- str);
+ if (_gtk_builder_enum_from_string (GTK_TYPE_ACCESSIBLE_INVALID_STATE, str, &value, error))
+ return gtk_invalid_accessible_value_new (value);
return NULL;
}
@@ -356,21 +350,12 @@ gtk_autocomplete_accessible_value_parse (const char *str,
gsize len,
GError **error)
{
+ int value;
+
g_return_val_if_fail (str == NULL || len == 0, NULL);
- if (strncmp (str, "none", 4) == 0)
- return gtk_autocomplete_accessible_value_new (GTK_ACCESSIBLE_AUTOCOMPLETE_NONE);
- else if (strncmp (str, "inline", 6) == 0)
- return gtk_autocomplete_accessible_value_new (GTK_ACCESSIBLE_AUTOCOMPLETE_INLINE);
- else if (strncmp (str, "list", 4) == 0)
- return gtk_autocomplete_accessible_value_new (GTK_ACCESSIBLE_AUTOCOMPLETE_LIST);
- else if (strncmp (str, "both", 4) == 0)
- return gtk_autocomplete_accessible_value_new (GTK_ACCESSIBLE_AUTOCOMPLETE_BOTH);
- else
- g_set_error (error, GTK_ACCESSIBLE_VALUE_ERROR,
- GTK_ACCESSIBLE_VALUE_ERROR_INVALID_TOKEN,
- "Unknown token “%s”",
- str);
+ if (_gtk_builder_enum_from_string (GTK_TYPE_ACCESSIBLE_AUTOCOMPLETE, str, &value, error))
+ return gtk_autocomplete_accessible_value_new (value);
return NULL;
}
@@ -419,17 +404,12 @@ gtk_orientation_accessible_value_parse (const char *str,
gsize len,
GError **error)
{
+ int value;
+
g_return_val_if_fail (str == NULL || len == 0, NULL);
- if (strncmp (str, "horizontal", 10) == 0)
- return gtk_orientation_accessible_value_new (GTK_ORIENTATION_HORIZONTAL);
- else if (strncmp (str, "vertical", 8) == 0)
- return gtk_orientation_accessible_value_new (GTK_ORIENTATION_VERTICAL);
- else
- g_set_error (error, GTK_ACCESSIBLE_VALUE_ERROR,
- GTK_ACCESSIBLE_VALUE_ERROR_INVALID_TOKEN,
- "Unknown token “%s”",
- str);
+ if (_gtk_builder_enum_from_string (GTK_TYPE_ORIENTATION, str, &value, error))
+ return gtk_orientation_accessible_value_new (value);
return NULL;
}
@@ -484,21 +464,12 @@ gtk_sort_accessible_value_parse (const char *str,
gsize len,
GError **error)
{
+ int value;
+
g_return_val_if_fail (str == NULL || len == 0, NULL);
- if (strncmp (str, "none", 4) == 0)
- return gtk_sort_accessible_value_new (GTK_ACCESSIBLE_SORT_NONE);
- else if (strncmp (str, "ascending", 9) == 0)
- return gtk_sort_accessible_value_new (GTK_ACCESSIBLE_SORT_ASCENDING);
- else if (strncmp (str, "descending", 10) == 0)
- return gtk_sort_accessible_value_new (GTK_ACCESSIBLE_SORT_DESCENDING);
- else if (strncmp (str, "other", 5) == 0)
- return gtk_sort_accessible_value_new (GTK_ACCESSIBLE_SORT_OTHER);
- else
- g_set_error (error, GTK_ACCESSIBLE_VALUE_ERROR,
- GTK_ACCESSIBLE_VALUE_ERROR_INVALID_TOKEN,
- "Unknown token “%s”",
- str);
+ if (_gtk_builder_enum_from_string (GTK_TYPE_ACCESSIBLE_SORT, str, &value, error))
+ return gtk_sort_accessible_value_new (value);
return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]