[gtk+/css-fixes: 2/15] css: Add _gtk_css_parser_try_enum
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/css-fixes: 2/15] css: Add _gtk_css_parser_try_enum
- Date: Fri, 25 Nov 2011 14:53:14 +0000 (UTC)
commit 1a68afffaf2b762910684a5436ccf5c57b2641d1
Author: Alexander Larsson <alexl redhat com>
Date: Fri Nov 25 14:11:56 2011 +0100
css: Add _gtk_css_parser_try_enum
This helps parsing GType enums in CSS, properly handling
CSS being case insensitive.
gtk/gtkcssparser.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkcssparserprivate.h | 3 ++
2 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index ff44c35..073e947 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -569,6 +569,53 @@ _gtk_css_parser_try_double (GtkCssParser *parser,
return TRUE;
}
+gboolean
+_gtk_css_parser_try_enum (GtkCssParser *parser,
+ GType enum_type,
+ int *value)
+{
+ GEnumClass *enum_class;
+ gboolean result;
+ const char *start;
+ char *str;
+
+ g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE);
+ g_return_val_if_fail (value != NULL, FALSE);
+
+ result = FALSE;
+
+ enum_class = g_type_class_ref (enum_type);
+
+ start = parser->data;
+
+ str = _gtk_css_parser_try_ident (parser, TRUE);
+ if (str == NULL)
+ return FALSE;
+
+ if (enum_class->n_values)
+ {
+ GEnumValue *enum_value;
+
+ for (enum_value = enum_class->values; enum_value->value_name; enum_value++)
+ {
+ if (enum_value->value_nick &&
+ g_ascii_strcasecmp (str, enum_value->value_nick) == 0)
+ {
+ *value = enum_value->value;
+ result = TRUE;
+ break;
+ }
+ }
+ }
+
+ g_type_class_unref (enum_class);
+
+ if (!result)
+ parser->data = start;
+
+ return result;
+}
+
typedef enum {
COLOR_RGBA,
COLOR_RGB,
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index 6ea60a8..dd58fa6 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -70,6 +70,9 @@ gboolean _gtk_css_parser_try_uint (GtkCssParser *parser
guint *value);
gboolean _gtk_css_parser_try_double (GtkCssParser *parser,
gdouble *value);
+gboolean _gtk_css_parser_try_enum (GtkCssParser *parser,
+ GType enum_type,
+ int *value);
void _gtk_css_parser_skip_whitespace (GtkCssParser *parser);
char * _gtk_css_parser_read_string (GtkCssParser *parser);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]