[gtk] cssparser: Add gtk_css_parser_consume_ident()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] cssparser: Add gtk_css_parser_consume_ident()
- Date: Fri, 12 Apr 2019 17:36:55 +0000 (UTC)
commit dbdb81f411b3e33b10d536ae9a418ed11055af54
Author: Benjamin Otte <otte redhat com>
Date: Sun Mar 31 12:40:53 2019 +0200
cssparser: Add gtk_css_parser_consume_ident()
And use it to fix the palette parser.
gtk/gtkcsspalettevalue.c | 7 +++----
gtk/gtkcssparser.c | 12 ++++++++++++
gtk/gtkcssparserprivate.h | 1 +
gtk/gtkcssstringvalue.c | 2 +-
gtk/gtkcssstylepropertyimpl.c | 11 +++++++----
5 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkcsspalettevalue.c b/gtk/gtkcsspalettevalue.c
index ac9088482c..3514ac6bbb 100644
--- a/gtk/gtkcsspalettevalue.c
+++ b/gtk/gtkcsspalettevalue.c
@@ -216,16 +216,15 @@ gtk_css_palette_value_parse (GtkCssParser *parser)
GtkCssValue *result, *color;
char *ident;
- if (_gtk_css_parser_try (parser, "default", TRUE))
+ if (gtk_css_parser_try_ident (parser, "default"))
return gtk_css_palette_value_new_default ();
result = gtk_css_palette_value_new_empty ();
do {
- ident = _gtk_css_parser_try_ident (parser, TRUE);
+ ident = gtk_css_parser_consume_ident (parser);
if (ident == NULL)
{
- _gtk_css_parser_error (parser, "expected color name");
_gtk_css_value_unref (result);
return NULL;
}
@@ -240,7 +239,7 @@ gtk_css_palette_value_parse (GtkCssParser *parser)
gtk_css_palette_value_add_color (result, ident, color);
g_free (ident);
- } while (_gtk_css_parser_try (parser, ",", TRUE));
+ } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
return result;
}
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index 9da98a8f6f..cd9970bbf0 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -779,6 +779,18 @@ _gtk_css_parser_try_double (GtkCssParser *parser,
return TRUE;
}
+char *
+gtk_css_parser_consume_ident (GtkCssParser *self)
+{
+ char *result;
+
+ result = _gtk_css_parser_try_ident (self, TRUE);
+ if (result == NULL)
+ _gtk_css_parser_error (self, "Expected an identifier");
+
+ return result;
+}
+
gboolean
gtk_css_parser_consume_number (GtkCssParser *self,
double *number)
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index e4b763a826..683246a6f8 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -96,6 +96,7 @@ gboolean _gtk_css_parser_try_double (GtkCssParser *parser
gboolean _gtk_css_parser_try_hash_color (GtkCssParser *parser,
GdkRGBA *rgba);
+char * gtk_css_parser_consume_ident (GtkCssParser *self);
gboolean gtk_css_parser_consume_number (GtkCssParser *self,
double *number);
gboolean gtk_css_parser_consume_function (GtkCssParser *self,
diff --git a/gtk/gtkcssstringvalue.c b/gtk/gtkcssstringvalue.c
index 49b7d19d4d..f6d0c2bf15 100644
--- a/gtk/gtkcssstringvalue.c
+++ b/gtk/gtkcssstringvalue.c
@@ -200,7 +200,7 @@ _gtk_css_ident_value_try_parse (GtkCssParser *parser)
g_return_val_if_fail (parser != NULL, NULL);
- ident = _gtk_css_parser_try_ident (parser, TRUE);
+ ident = gtk_css_parser_consume_ident (parser);
if (ident == NULL)
return NULL;
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index ed41c912db..a12685655a 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -159,13 +159,16 @@ font_family_parse_one (GtkCssParser *parser)
{
char *name;
- name = _gtk_css_parser_try_ident (parser, TRUE);
- if (name)
+ if (gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_IDENT))
{
- GString *string = g_string_new (name);
+ GString *string = g_string_new (NULL);
+
+ name = gtk_css_parser_consume_ident (parser);
+ g_string_append (string, name);
g_free (name);
- while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
+ while (gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_IDENT))
{
+ name = gtk_css_parser_consume_ident (parser);
g_string_append_c (string, ' ');
g_string_append (string, name);
g_free (name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]