cssimagerecolor: Use gtk_css_parser_consume_function()

This commit is contained in:
Benjamin Otte 2019-03-30 20:20:11 +01:00
parent 3988847a05
commit 45bc4ed321

View File

@ -235,49 +235,50 @@ gtk_css_image_recolor_compute (GtkCssImage *image,
return img; return img;
} }
static guint
gtk_css_image_recolor_parse_arg (GtkCssParser *parser,
guint arg,
gpointer data)
{
GtkCssImageRecolor *self = data;
switch (arg)
{
case 0:
self->file = _gtk_css_parser_read_url (parser);
if (self->file == NULL)
{
_gtk_css_parser_error (parser, "Expected a url here");
return 0;
}
return 1;
case 1:
self->palette = gtk_css_palette_value_parse (parser);
if (self->palette == NULL)
{
_gtk_css_parser_error (parser, "A palette is required here");
return 0;
}
return 1;
default:
g_assert_not_reached ();
return 0;
}
}
static gboolean static gboolean
gtk_css_image_recolor_parse (GtkCssImage *image, gtk_css_image_recolor_parse (GtkCssImage *image,
GtkCssParser *parser) GtkCssParser *parser)
{ {
GtkCssImageRecolor *recolor = GTK_CSS_IMAGE_RECOLOR (image); if (!gtk_css_parser_has_function (parser, "-gtk-recolor"))
if (!_gtk_css_parser_try (parser, "-gtk-recolor", TRUE))
{ {
_gtk_css_parser_error (parser, "'-gtk-recolor'"); _gtk_css_parser_error (parser, "Expected '-gtk-recolor('");
return FALSE; return FALSE;
} }
if (!_gtk_css_parser_try (parser, "(", TRUE)) return gtk_css_parser_consume_function (parser, 1, 2, gtk_css_image_recolor_parse_arg, image);
{
_gtk_css_parser_error (parser, "Expected '(' after '-gtk-recolor'");
return FALSE;
}
recolor->file = _gtk_css_parser_read_url (parser);
if (recolor->file == NULL)
{
_gtk_css_parser_error (parser, "Expected a url here");
return FALSE;
}
if ( _gtk_css_parser_try (parser, ",", TRUE))
{
recolor->palette = gtk_css_palette_value_parse (parser);
if (recolor->palette == NULL)
{
_gtk_css_parser_error (parser, "A palette is required here");
return FALSE;
}
}
if (!_gtk_css_parser_try (parser, ")", TRUE))
{
_gtk_css_parser_error (parser,
"Expected ')' at end of '-gtk-recolor'");
return FALSE;
}
return TRUE;
} }
static int static int