diff options
author | Benjamin Otte <otte@redhat.com> | 2016-04-03 03:59:50 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2016-04-08 16:18:32 +0200 |
commit | 55e3a1927d232f3fbbc235fceda3411c7936c57e (patch) | |
tree | 345d28f8944fbe1e9ead7c68e69cad67070a8ead | |
parent | b00e9f629ca07347eec09a305e33159e99c7256a (diff) | |
download | gtk+-55e3a1927d232f3fbbc235fceda3411c7936c57e.tar.gz |
css: Add gtk_css_token_source_consume_integer()
And make sure the integer parsing functions call it.
-rw-r--r-- | gtk/gtkcsscolorvalue.c | 10 | ||||
-rw-r--r-- | gtk/gtkcsseasevalue.c | 19 | ||||
-rw-r--r-- | gtk/gtkcsstokensource.c | 21 | ||||
-rw-r--r-- | gtk/gtkcsstokensourceprivate.h | 2 |
4 files changed, 31 insertions, 21 deletions
diff --git a/gtk/gtkcsscolorvalue.c b/gtk/gtkcsscolorvalue.c index d2347db18c..49cab87596 100644 --- a/gtk/gtkcsscolorvalue.c +++ b/gtk/gtkcsscolorvalue.c @@ -1109,16 +1109,8 @@ gtk_css_color_value_token_parse (GtkCssTokenSource *source) } gtk_css_token_source_consume_token (source); } - else if (gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER) || - gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER)) + else if (!gtk_css_token_source_consume_integer (source, &id)) { - id = token->number.number; - gtk_css_token_source_consume_token (source); - } - else - { - gtk_css_token_source_error (source, "Expected a valid integer value"); - gtk_css_token_source_consume_all (source); gtk_win32_theme_unref (theme); return NULL; } diff --git a/gtk/gtkcsseasevalue.c b/gtk/gtkcsseasevalue.c index 72f7a3775c..4a638ec526 100644 --- a/gtk/gtkcsseasevalue.c +++ b/gtk/gtkcsseasevalue.c @@ -37,7 +37,7 @@ struct _GtkCssValue { double y2; } cubic; struct { - guint steps; + int steps; gboolean start; } steps; } u; @@ -125,7 +125,7 @@ gtk_css_value_ease_print (const GtkCssValue *ease, } else { - g_string_append_printf (string, "steps(%u%s)", ease->u.steps.steps, ease->u.steps.start ? ",start" : ""); + g_string_append_printf (string, "steps(%d%s)", ease->u.steps.steps, ease->u.steps.start ? ",start" : ""); } break; default: @@ -167,7 +167,7 @@ _gtk_css_ease_value_new_cubic_bezier (double x1, } static GtkCssValue * -_gtk_css_ease_value_new_steps (guint n_steps, +_gtk_css_ease_value_new_steps (gint n_steps, gboolean start) { GtkCssValue *value; @@ -359,20 +359,15 @@ token_parse_steps (GtkCssTokenSource *source, token = gtk_css_token_source_get_token (source); if (nth_argument == 0) { - if (!gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER)) - { - gtk_css_token_source_error (source, "Expected a positive integer for number of steps"); - gtk_css_token_source_consume_all (source); - return 0; - } - else if (token->number.number <= 0) + if (!gtk_css_token_source_consume_integer (source, &value->u.steps.steps)) + return 0; + + if (value->u.steps.steps <= 0) { gtk_css_token_source_error (source, "Number of steps must be greater than 0"); gtk_css_token_source_consume_all (source); return 0; } - value->u.steps.steps = token->number.number; - gtk_css_token_source_consume_token (source); return 1; } else diff --git a/gtk/gtkcsstokensource.c b/gtk/gtkcsstokensource.c index 994086f851..1e3d0f249b 100644 --- a/gtk/gtkcsstokensource.c +++ b/gtk/gtkcsstokensource.c @@ -438,6 +438,27 @@ gtk_css_token_source_consume_number (GtkCssTokenSource *source, return TRUE; } +gboolean +gtk_css_token_source_consume_integer (GtkCssTokenSource *source, + int *number) +{ + const GtkCssToken *token; + + token = gtk_css_token_source_get_token (source); + if (gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNED_INTEGER) || + gtk_css_token_is (token, GTK_CSS_TOKEN_SIGNLESS_INTEGER)) + { + *number = token->number.number; + gtk_css_token_source_consume_token (source); + return TRUE; + } + + /* XXX: parse calc() */ + gtk_css_token_source_error (source, "Expected an integer"); + gtk_css_token_source_consume_all (source); + return FALSE; +} + GFile * gtk_css_token_source_resolve_url (GtkCssTokenSource *source, const char *url) diff --git a/gtk/gtkcsstokensourceprivate.h b/gtk/gtkcsstokensourceprivate.h index 6748cb5512..65df9949cc 100644 --- a/gtk/gtkcsstokensourceprivate.h +++ b/gtk/gtkcsstokensourceprivate.h @@ -74,6 +74,8 @@ gboolean gtk_css_token_source_consume_function (GtkCssTokenSour gpointer data); gboolean gtk_css_token_source_consume_number (GtkCssTokenSource *source, double *number); +gboolean gtk_css_token_source_consume_integer (GtkCssTokenSource *source, + int *number); GFile * gtk_css_token_source_resolve_url (GtkCssTokenSource *source, const char *url); GFile * gtk_css_token_source_consume_url (GtkCssTokenSource *source); |