From d9ef734458bf1a2a394c5962787a6351d42f57c6 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 22 Mar 2019 17:37:04 +0100 Subject: [PATCH] cssparser: Simplify Remove the uint parser (and use the int parser in the one user of it). And avoid unnecessarily going through a macro. --- gtk/gtkcsseasevalue.c | 9 +++++++-- gtk/gtkcssparser.c | 38 +++++++------------------------------- gtk/gtkcssparserprivate.h | 6 +----- 3 files changed, 15 insertions(+), 38 deletions(-) diff --git a/gtk/gtkcsseasevalue.c b/gtk/gtkcsseasevalue.c index a9ab9dce40..ab990af38e 100644 --- a/gtk/gtkcsseasevalue.c +++ b/gtk/gtkcsseasevalue.c @@ -254,7 +254,7 @@ gtk_css_ease_value_parse_cubic_bezier (GtkCssParser *parser) static GtkCssValue * gtk_css_ease_value_parse_steps (GtkCssParser *parser) { - guint n_steps; + int n_steps; gboolean start; if (!_gtk_css_parser_try (parser, "(", TRUE)) @@ -263,11 +263,16 @@ gtk_css_ease_value_parse_steps (GtkCssParser *parser) return NULL; } - if (!_gtk_css_parser_try_uint (parser, &n_steps)) + if (!_gtk_css_parser_try_int (parser, &n_steps)) { _gtk_css_parser_error (parser, "Expected number of steps"); return NULL; } + else if (n_steps < 1) + { + _gtk_css_parser_error (parser, "Number of steps must be > 0"); + return NULL; + } if (_gtk_css_parser_try (parser, ",", TRUE)) { diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c index 6f4404db75..25b86f3cb8 100644 --- a/gtk/gtkcssparser.c +++ b/gtk/gtkcssparser.c @@ -281,14 +281,17 @@ _gtk_css_parser_skip_whitespace (GtkCssParser *parser) } gboolean -gtk_css_parser_try_len (GtkCssParser *parser, - const char *string, - gsize string_len, - gboolean skip_whitespace) +_gtk_css_parser_try (GtkCssParser *parser, + const char *string, + gboolean skip_whitespace) { + gsize string_len; + g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE); g_return_val_if_fail (string != NULL, FALSE); + string_len = strlen (string); + if (g_ascii_strncasecmp (parser->data, string, string_len) != 0) return FALSE; @@ -562,33 +565,6 @@ _gtk_css_parser_try_int (GtkCssParser *parser, return TRUE; } -gboolean -_gtk_css_parser_try_uint (GtkCssParser *parser, - guint *value) -{ - guint64 result; - char *end; - - g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE); - g_return_val_if_fail (value != NULL, FALSE); - - errno = 0; - result = g_ascii_strtoull (parser->data, &end, 10); - if (errno) - return FALSE; - if (result > G_MAXUINT) - return FALSE; - if (parser->data == end) - return FALSE; - - parser->data = end; - *value = result; - - _gtk_css_parser_skip_whitespace (parser); - - return TRUE; -} - gboolean _gtk_css_parser_try_double (GtkCssParser *parser, gdouble *value) diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h index e5acde65e9..73b498a4fa 100644 --- a/gtk/gtkcssparserprivate.h +++ b/gtk/gtkcssparserprivate.h @@ -61,10 +61,8 @@ gboolean _gtk_css_parser_is_string (GtkCssParser *parser * however is fine to call if you don’t know yet if the token is a foo or a bar, * you can _try_bar() if try_foo() failed. */ -#define _gtk_css_parser_try(p, s, skip) (gtk_css_parser_try_len (p, s, strlen(s), skip)) -gboolean gtk_css_parser_try_len (GtkCssParser *parser, +gboolean _gtk_css_parser_try (GtkCssParser *parser, const char *string, - gsize string_len, gboolean skip_whitespace); char * _gtk_css_parser_try_ident (GtkCssParser *parser, gboolean skip_whitespace); @@ -72,8 +70,6 @@ char * _gtk_css_parser_try_name (GtkCssParser *parser gboolean skip_whitespace); gboolean _gtk_css_parser_try_int (GtkCssParser *parser, int *value); -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_hash_color (GtkCssParser *parser,