[gtk+/wip/otte/tokenizer: 69/78] css: Add gtk_css_token_source_consume_integer()



commit 55e3a1927d232f3fbbc235fceda3411c7936c57e
Author: Benjamin Otte <otte redhat com>
Date:   Sun Apr 3 03:59:50 2016 +0200

    css: Add gtk_css_token_source_consume_integer()
    
    And make sure the integer parsing functions call it.

 gtk/gtkcsscolorvalue.c         |   10 +---------
 gtk/gtkcsseasevalue.c          |   19 +++++++------------
 gtk/gtkcsstokensource.c        |   21 +++++++++++++++++++++
 gtk/gtkcsstokensourceprivate.h |    2 ++
 4 files changed, 31 insertions(+), 21 deletions(-)
---
diff --git a/gtk/gtkcsscolorvalue.c b/gtk/gtkcsscolorvalue.c
index d2347db..49cab87 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 72f7a37..4a638ec 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 994086f..1e3d0f2 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 6748cb5..65df994 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);


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