[gtk/wip/otte/css: 15/52] cssparser: Get rid of _gtk_css_parser_try_double()



commit e34669b27d5021a8fc8c1bc96a246baf736e688f
Author: Benjamin Otte <otte redhat com>
Date:   Fri Apr 5 02:16:00 2019 +0200

    cssparser: Get rid of _gtk_css_parser_try_double()
    
    Use gtk_css_parser_consume_number() everywhere instead.

 gtk/gtkcsscolorvalue.c    | 18 ++++++------------
 gtk/gtkcsskeyframes.c     |  2 +-
 gtk/gtkcssparser.c        | 37 ++++++++++++++-----------------------
 gtk/gtkcssparserprivate.h |  2 --
 4 files changed, 21 insertions(+), 38 deletions(-)
---
diff --git a/gtk/gtkcsscolorvalue.c b/gtk/gtkcsscolorvalue.c
index 93aec028b0..0735d1e9f4 100644
--- a/gtk/gtkcsscolorvalue.c
+++ b/gtk/gtkcsscolorvalue.c
@@ -548,11 +548,9 @@ _gtk_css_color_value_parse_function (GtkCssParser   *parser,
               return NULL;
             }
 
-          if (!_gtk_css_parser_try_double (parser, &tmp))
-            {
-              _gtk_css_parser_error (parser, "Invalid number for color value");
-              return NULL;
-            }
+          if (!gtk_css_parser_consume_number (parser, &tmp))
+            return NULL;
+
           if (_gtk_css_parser_try (parser, "%", TRUE))
             tmp /= 100.0;
           else
@@ -575,11 +573,8 @@ _gtk_css_color_value_parse_function (GtkCssParser   *parser,
               return NULL;
             }
 
-          if (!_gtk_css_parser_try_double (parser, &rgba.alpha))
-            {
-              _gtk_css_parser_error (parser, "Invalid number for alpha value");
-              return NULL;
-            }
+          if (!gtk_css_parser_consume_number (parser, &rgba.alpha))
+            return NULL;
         }
       else
         rgba.alpha = 1.0;
@@ -626,9 +621,8 @@ _gtk_css_color_value_parse_function (GtkCssParser   *parser,
               return NULL;
             }
 
-          if (!_gtk_css_parser_try_double (parser, &d))
+          if (!gtk_css_parser_consume_number (parser, &d))
             {
-              _gtk_css_parser_error (parser, "Expected number in color definition");
               _gtk_css_value_unref (child1);
               if (child2)
                 _gtk_css_value_unref (child2);
diff --git a/gtk/gtkcsskeyframes.c b/gtk/gtkcsskeyframes.c
index 12344965a4..891da2ea59 100644
--- a/gtk/gtkcsskeyframes.c
+++ b/gtk/gtkcsskeyframes.c
@@ -339,7 +339,7 @@ _gtk_css_keyframes_parse (GtkCssParser *parser)
         progress = 0;
       else if (gtk_css_parser_try_ident (parser, "to"))
         progress = 1;
-      else if (_gtk_css_parser_try_double (parser, &progress) &&
+      else if (gtk_css_parser_consume_number (parser, &progress) &&
                _gtk_css_parser_try (parser, "%", TRUE))
         {
           if (progress < 0 || progress > 100)
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index 49ba8fe1dc..3d0b31d03d 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -775,26 +775,28 @@ _gtk_css_parser_try_int (GtkCssParser *parser,
 }
 
 gboolean
-_gtk_css_parser_try_double (GtkCssParser *parser,
-                            gdouble      *value)
+gtk_css_parser_consume_number (GtkCssParser *self,
+                               double       *number)
 {
   gdouble result;
   char *end;
 
-  g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE);
-  g_return_val_if_fail (value != NULL, FALSE);
+  g_return_val_if_fail (GTK_IS_CSS_PARSER (self), FALSE);
+  g_return_val_if_fail (number != NULL, FALSE);
 
   errno = 0;
-  result = g_ascii_strtod (parser->data, &end);
-  if (errno)
-    return FALSE;
-  if (parser->data == end)
-    return FALSE;
+  result = g_ascii_strtod (self->data, &end);
+  if (errno ||
+      self->data == end)
+    {
+      _gtk_css_parser_error (self, "Expected a number");
+      return FALSE;
+    }
 
-  parser->data = end;
-  *value = result;
+  self->data = end;
+  *number = result;
 
-  _gtk_css_parser_skip_whitespace (parser);
+  _gtk_css_parser_skip_whitespace (self);
 
   return TRUE;
 }
@@ -811,17 +813,6 @@ gtk_css_parser_consume_ident (GtkCssParser *self)
   return result;
 }
 
-gboolean
-gtk_css_parser_consume_number (GtkCssParser *self,
-                               double       *number)
-{
-  if (_gtk_css_parser_try_double (self, number))
-    return TRUE;
-  
-  _gtk_css_parser_error (self, "Expected a number");
-  return FALSE;
-}
-
 gboolean
 _gtk_css_parser_has_number (GtkCssParser *parser)
 {
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index 82474ff378..60f2d544d9 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -92,8 +92,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_double        (GtkCssParser          *parser,
-                                                   gdouble               *value);
 gboolean        _gtk_css_parser_try_hash_color    (GtkCssParser          *parser,
                                                    GdkRGBA               *rgba);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]