[gtk/wip/otte/css: 34/66] cssparser: Add gtk_css_parser_try_delim()



commit 3f01167cfbd6dcb228245da1ca45ee180afa0470
Author: Benjamin Otte <otte redhat com>
Date:   Fri Apr 5 02:57:14 2019 +0200

    cssparser: Add gtk_css_parser_try_delim()
    
    For parsing single code point delimiters. Also port calc() to use this.

 gtk/gtkcsscalcvalue.c             |  8 ++++----
 gtk/gtkcssparser.c                | 11 +++++++++++
 gtk/gtkcssparserprivate.h         |  2 ++
 gtk/gtkcssshorthandpropertyimpl.c |  6 +++---
 4 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkcsscalcvalue.c b/gtk/gtkcsscalcvalue.c
index f9279e7649..129dd93c52 100644
--- a/gtk/gtkcsscalcvalue.c
+++ b/gtk/gtkcsscalcvalue.c
@@ -366,7 +366,7 @@ gtk_css_calc_value_parse_product (GtkCssParser           *parser,
       if (actual_flags != GTK_CSS_PARSE_NUMBER && !is_number (result))
         actual_flags = GTK_CSS_PARSE_NUMBER;
 
-      if (_gtk_css_parser_try (parser, "*", TRUE))
+      if (gtk_css_parser_try_delim (parser, '*'))
         {
           value = gtk_css_calc_value_parse_product (parser, actual_flags);
           if (value == NULL)
@@ -379,7 +379,7 @@ gtk_css_calc_value_parse_product (GtkCssParser           *parser,
           _gtk_css_value_unref (result);
           result = temp;
         }
-      else if (_gtk_css_parser_try (parser, "/", TRUE))
+      else if (gtk_css_parser_try_delim (parser, '/'))
         {
           value = gtk_css_calc_value_parse_product (parser, GTK_CSS_PARSE_NUMBER);
           if (value == NULL)
@@ -422,13 +422,13 @@ gtk_css_calc_value_parse_sum (GtkCssParser           *parser,
     {
       GtkCssValue *next, *temp;
 
-      if (_gtk_css_parser_try (parser, "+", TRUE))
+      if (gtk_css_parser_try_delim (parser, '+'))
         {
           next = gtk_css_calc_value_parse_product (parser, flags);
           if (next == NULL)
             goto fail;
         }
-      else if (_gtk_css_parser_try (parser, "-", TRUE))
+      else if (gtk_css_parser_try_delim (parser, '-'))
         {
           temp = gtk_css_calc_value_parse_product (parser, flags);
           if (temp == NULL)
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index 3d0b31d03d..7599cf558c 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -320,6 +320,17 @@ gtk_css_parser_try_ident (GtkCssParser *parser,
   return TRUE;
 }
 
+gboolean
+gtk_css_parser_try_delim (GtkCssParser *parser,
+                          gunichar      delim)
+{
+  if (*parser->data != delim)
+    return FALSE;
+  parser->data += 1;
+  _gtk_css_parser_skip_whitespace (parser);
+  return TRUE;
+}
+
 gboolean
 gtk_css_parser_try_token (GtkCssParser    *parser,
                           GtkCssTokenType  type)
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index 60f2d544d9..5354f7a0f6 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -79,6 +79,8 @@ gboolean        gtk_css_parser_has_function       (GtkCssParser          *parser
  */
 gboolean        gtk_css_parser_try_ident          (GtkCssParser          *parser,
                                                    const char            *ident);
+gboolean        gtk_css_parser_try_delim          (GtkCssParser          *parser,
+                                                   gunichar               delim);
 gboolean        gtk_css_parser_try_at_keyword     (GtkCssParser          *parser,
                                                    const char            *keyword);
 gboolean        gtk_css_parser_try_token          (GtkCssParser          *parser,
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 0f14bf9524..95bc8b6dc1 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -155,7 +155,7 @@ parse_border_radius (GtkCssShorthandProperty  *shorthand,
   for (; i < 4; i++)
     x[i] = _gtk_css_value_ref (x[(i - 1) >> 1]);
 
-  if (_gtk_css_parser_try (parser, "/", TRUE))
+  if (gtk_css_parser_try_delim (parser, '/'))
     {
       for (i = 0; i < 4; i++)
         {
@@ -293,7 +293,7 @@ parse_border_image (GtkCssShorthandProperty  *shorthand,
           if (values[1] == NULL)
             return FALSE;
 
-          if (_gtk_css_parser_try (parser, "/", TRUE))
+          if (gtk_css_parser_try_delim (parser, '/'))
             {
               values[2] = _gtk_css_border_value_parse (parser,
                                                        GTK_CSS_PARSE_PERCENT
@@ -529,7 +529,7 @@ parse_one_background (GtkCssShorthandProperty  *shorthand,
           values[1] = value;
           value = NULL;
 
-          if (_gtk_css_parser_try (parser, "/", TRUE) &&
+          if (gtk_css_parser_try_delim (parser, '/') &&
               (value = _gtk_css_bg_size_value_parse (parser)))
             {
               values[2] = value;


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