[gtk/wip/otte/css: 169/225] cssparser: Get rid of _gtk_css_parser_begins_with()



commit 980b1bc77be1e03125e78c8bd450e0fb47911c16
Author: Benjamin Otte <otte redhat com>
Date:   Sun Mar 24 03:56:31 2019 +0100

    cssparser: Get rid of _gtk_css_parser_begins_with()
    
    Replace it with calls to gtk_css_parser_has_token().

 gtk/gtkcsscalcvalue.c             | 10 ++++------
 gtk/gtkcssfiltervalue.c           |  2 +-
 gtk/gtkcsskeyframes.c             |  4 ++--
 gtk/gtkcssparser.c                |  9 ---------
 gtk/gtkcssparserprivate.h         |  2 --
 gtk/gtkcssprovider.c              | 10 +++++-----
 gtk/gtkcssselector.c              |  4 ++--
 gtk/gtkcssshadowvalue.c           |  6 +++---
 gtk/gtkcssshorthandpropertyimpl.c |  8 ++++----
 gtk/gtkcssstylepropertyimpl.c     |  6 +++---
 gtk/gtkcsstransformvalue.c        |  2 +-
 11 files changed, 25 insertions(+), 38 deletions(-)
---
diff --git a/gtk/gtkcsscalcvalue.c b/gtk/gtkcsscalcvalue.c
index d1a31d722e..3b3b133273 100644
--- a/gtk/gtkcsscalcvalue.c
+++ b/gtk/gtkcsscalcvalue.c
@@ -361,7 +361,7 @@ gtk_css_calc_value_parse_product (GtkCssParser           *parser,
   if (result == NULL)
     return NULL;
 
-  while (_gtk_css_parser_begins_with (parser, '*') || _gtk_css_parser_begins_with (parser, '/'))
+  while (TRUE)
     {
       if (actual_flags != GTK_CSS_PARSE_NUMBER && !is_number (result))
         actual_flags = GTK_CSS_PARSE_NUMBER;
@@ -391,8 +391,7 @@ gtk_css_calc_value_parse_product (GtkCssParser           *parser,
         }
       else
         {
-          g_assert_not_reached ();
-          goto fail;
+          break;
         }
     }
 
@@ -419,7 +418,7 @@ gtk_css_calc_value_parse_sum (GtkCssParser           *parser,
   if (result == NULL)
     return NULL;
 
-  while (_gtk_css_parser_begins_with (parser, '+') || _gtk_css_parser_begins_with (parser, '-'))
+  while (TRUE)
     {
       GtkCssValue *next, *temp;
 
@@ -439,8 +438,7 @@ gtk_css_calc_value_parse_sum (GtkCssParser           *parser,
         }
       else
         {
-          g_assert_not_reached ();
-          goto fail;
+          break;
         }
 
       temp = gtk_css_number_value_add (result, next);
diff --git a/gtk/gtkcssfiltervalue.c b/gtk/gtkcssfiltervalue.c
index eaf79de37c..532efd0a1f 100644
--- a/gtk/gtkcssfiltervalue.c
+++ b/gtk/gtkcssfiltervalue.c
@@ -846,7 +846,7 @@ gtk_css_filter_value_parse (GtkCssParser *parser)
         return NULL;
       }
     g_array_append_val (array, filter);
-  } while (!_gtk_css_parser_begins_with (parser, ';'));
+  } while (!gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_SEMICOLON));
 
   value = gtk_css_filter_value_alloc (array->len);
   memcpy (value->filters, array->data, sizeof (GtkCssFilter) * array->len);
diff --git a/gtk/gtkcsskeyframes.c b/gtk/gtkcsskeyframes.c
index 267012aa55..a45a5fd584 100644
--- a/gtk/gtkcsskeyframes.c
+++ b/gtk/gtkcsskeyframes.c
@@ -257,7 +257,7 @@ parse_declaration (GtkCssKeyframes *keyframes,
     return FALSE;
 
   if (!_gtk_css_parser_try (parser, ";", TRUE) &&
-      !_gtk_css_parser_begins_with (parser, '}'))
+      !gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_CLOSE_CURLY))
     {
       _gtk_css_parser_error (parser, "Junk at end of value");
       _gtk_css_value_unref (value);
@@ -333,7 +333,7 @@ _gtk_css_keyframes_parse (GtkCssParser *parser)
 
   keyframes = gtk_css_keyframes_new ();
 
-  while (!_gtk_css_parser_begins_with (parser, '}'))
+  while (!gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_CLOSE_CURLY))
     {
       if (_gtk_css_parser_try (parser, "from", TRUE))
         progress = 0;
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index 5a786df8c3..650271e4a5 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -98,15 +98,6 @@ _gtk_css_parser_is_eof (GtkCssParser *parser)
   return *parser->data == 0;
 }
 
-gboolean
-_gtk_css_parser_begins_with (GtkCssParser *parser,
-                             char          c)
-{
-  g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), TRUE);
-
-  return *parser->data == c;
-}
-
 gboolean
 _gtk_css_parser_has_prefix (GtkCssParser *parser,
                             const char   *prefix)
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index 861d5db677..06be9e3a31 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -50,8 +50,6 @@ GFile *         _gtk_css_parser_get_file_for_path (GtkCssParser          *parser
                                                    const char            *path);
 
 gboolean        _gtk_css_parser_is_eof            (GtkCssParser          *parser);
-gboolean        _gtk_css_parser_begins_with       (GtkCssParser          *parser,
-                                                   char                   c);
 gboolean        _gtk_css_parser_has_prefix        (GtkCssParser          *parser,
                                                    const char            *prefix);
 gboolean        gtk_css_parser_has_token          (GtkCssParser          *parser,
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index f91ce9b0d1..635a92263f 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1049,8 +1049,8 @@ parse_declaration (GtkCssScanner *scanner,
           return;
         }
 
-      if (!_gtk_css_parser_begins_with (scanner->parser, ';') &&
-          !_gtk_css_parser_begins_with (scanner->parser, '}') &&
+      if (!gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_SEMICOLON) &&
+          !gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_CLOSE_CURLY) &&
           !_gtk_css_parser_is_eof (scanner->parser))
         {
           gtk_css_provider_error (scanner->provider,
@@ -1100,7 +1100,7 @@ check_for_semicolon:
 
   if (!_gtk_css_parser_try (scanner->parser, ";", TRUE))
     {
-      if (!_gtk_css_parser_begins_with (scanner->parser, '}') &&
+      if (!gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_CLOSE_CURLY) &&
           !_gtk_css_parser_is_eof (scanner->parser))
         {
           gtk_css_provider_error_literal (scanner->provider,
@@ -1118,7 +1118,7 @@ parse_declarations (GtkCssScanner *scanner,
                     GtkCssRuleset *ruleset)
 {
   while (!_gtk_css_parser_is_eof (scanner->parser) &&
-         !_gtk_css_parser_begins_with (scanner->parser, '}'))
+         !gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_CLOSE_CURLY))
     {
       parse_declaration (scanner, ruleset);
     }
@@ -1178,7 +1178,7 @@ parse_ruleset (GtkCssScanner *scanner)
 static void
 parse_statement (GtkCssScanner *scanner)
 {
-  if (_gtk_css_parser_begins_with (scanner->parser, '@'))
+  if (gtk_css_parser_has_token (scanner->parser, GTK_CSS_TOKEN_AT_KEYWORD))
     parse_at_keyword (scanner);
   else
     parse_ruleset (scanner);
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 4fc9bb42a4..1e207221c5 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -1264,8 +1264,8 @@ _gtk_css_selector_parse (GtkCssParser *parser)
 
   while ((selector = parse_simple_selector (parser, selector)) &&
          !_gtk_css_parser_is_eof (parser) &&
-         !_gtk_css_parser_begins_with (parser, ',') &&
-         !_gtk_css_parser_begins_with (parser, '{'))
+         !gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_COMMA) &&
+         !gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_OPEN_CURLY))
     {
       if (_gtk_css_parser_try (parser, "+", TRUE))
         selector = gtk_css_selector_new (&GTK_CSS_SELECTOR_ADJACENT, selector);
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 7e6c41c17d..1a3dc68445 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -205,9 +205,9 @@ static gboolean
 value_is_done_parsing (GtkCssParser *parser)
 {
   return _gtk_css_parser_is_eof (parser) ||
-         _gtk_css_parser_begins_with (parser, ',') ||
-         _gtk_css_parser_begins_with (parser, ';') ||
-         _gtk_css_parser_begins_with (parser, '}');
+         gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_COMMA) ||
+         gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_SEMICOLON) ||
+         gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_CLOSE_CURLY);
 }
 
 GtkCssValue *
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index be88cc672b..b9b7cfdea5 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -51,9 +51,9 @@ static gboolean
 value_is_done_parsing (GtkCssParser *parser)
 {
   return _gtk_css_parser_is_eof (parser) ||
-         _gtk_css_parser_begins_with (parser, ',') ||
-         _gtk_css_parser_begins_with (parser, ';') ||
-         _gtk_css_parser_begins_with (parser, '}');
+         gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_COMMA) ||
+         gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_SEMICOLON) ||
+         gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_CLOSE_CURLY);
 }
 
 static gboolean
@@ -617,7 +617,7 @@ parse_one_transition (GtkCssShorthandProperty  *shorthand,
     {
       /* the image part */
       if (values[2] == NULL &&
-          gtk_css_number_value_can_parse (parser) && !_gtk_css_parser_begins_with (parser, '-'))
+          gtk_css_number_value_can_parse (parser))
         {
           GtkCssValue *number = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_TIME);
 
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index e13710386a..f3a0e50e52 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -466,9 +466,9 @@ static gboolean
 value_is_done_parsing (GtkCssParser *parser)
 {
   return _gtk_css_parser_is_eof (parser) ||
-         _gtk_css_parser_begins_with (parser, ',') ||
-         _gtk_css_parser_begins_with (parser, ';') ||
-         _gtk_css_parser_begins_with (parser, '}');
+         gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_COMMA) ||
+         gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_SEMICOLON) ||
+         gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_CLOSE_CURLY);
 }
 
 static GtkCssValue *
diff --git a/gtk/gtkcsstransformvalue.c b/gtk/gtkcsstransformvalue.c
index 51e9a06fdc..74df4a7321 100644
--- a/gtk/gtkcsstransformvalue.c
+++ b/gtk/gtkcsstransformvalue.c
@@ -1179,7 +1179,7 @@ _gtk_css_transform_value_parse (GtkCssParser *parser)
         return NULL;
       }
     g_array_append_val (array, transform);
-  } while (!_gtk_css_parser_begins_with (parser, ';'));
+  } while (!gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_SEMICOLON));
 
   value = gtk_css_transform_value_alloc (array->len);
   memcpy (value->transforms, array->data, sizeof (GtkCssTransform) * array->len);


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