[gtk/wip/otte/css: 15/28] cssparser: Add gtk_css_parser_consume_ident()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/css: 15/28] cssparser: Add gtk_css_parser_consume_ident()
- Date: Sat, 6 Apr 2019 00:51:52 +0000 (UTC)
commit 8909d1cc49964c18ac11e3959b178cf234cbfeb6
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/gtkcssstylepropertyimpl.c | 10 ++++++----
4 files changed, 22 insertions(+), 8 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 30fa04088a..8b51bdbd8f 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -774,6 +774,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/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index ed41c912db..2f61397ef9 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -159,13 +159,15 @@ 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_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]