[gtk/wip/otte/css: 23/35] cssparser: Drop _gtk_css_parser_has_prefix()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/css: 23/35] cssparser: Drop _gtk_css_parser_has_prefix()
- Date: Tue, 9 Apr 2019 04:04:44 +0000 (UTC)
commit c2649b30624d68413e900ea2e399108b05d5f63c
Author: Benjamin Otte <otte redhat com>
Date: Mon Apr 1 11:47:53 2019 +0200
cssparser: Drop _gtk_css_parser_has_prefix()
Replace it with has_ident/has_function. The old function is a typical
string matching API, not a tokenizing one.
gtk/gtkcsscalcvalue.c | 2 +-
gtk/gtkcsseasevalue.c | 12 ++++++++++--
gtk/gtkcssimage.c | 2 +-
gtk/gtkcssnumbervalue.c | 4 ++--
gtk/gtkcssparser.c | 24 +++++++++++++++---------
gtk/gtkcssparserprivate.h | 4 ++--
gtk/gtkcssselector.c | 2 +-
gtk/gtkcssshorthandpropertyimpl.c | 4 ++--
8 files changed, 34 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkcsscalcvalue.c b/gtk/gtkcsscalcvalue.c
index 3b3b133273..f9279e7649 100644
--- a/gtk/gtkcsscalcvalue.c
+++ b/gtk/gtkcsscalcvalue.c
@@ -316,7 +316,7 @@ static GtkCssValue *
gtk_css_calc_value_parse_value (GtkCssParser *parser,
GtkCssNumberParseFlags flags)
{
- if (_gtk_css_parser_has_prefix (parser, "calc"))
+ if (gtk_css_parser_has_function (parser, "calc"))
{
_gtk_css_parser_error (parser, "Nested calc() expressions are not allowed.");
return NULL;
diff --git a/gtk/gtkcsseasevalue.c b/gtk/gtkcsseasevalue.c
index 1a1e66c92a..7dc851cd5b 100644
--- a/gtk/gtkcsseasevalue.c
+++ b/gtk/gtkcsseasevalue.c
@@ -209,8 +209,16 @@ _gtk_css_ease_value_can_parse (GtkCssParser *parser)
for (i = 0; i < G_N_ELEMENTS (parser_values); i++)
{
- if (_gtk_css_parser_has_prefix (parser, parser_values[i].name))
- return TRUE;
+ if (parser_values[i].is_function)
+ {
+ if (gtk_css_parser_has_function (parser, parser_values[i].name))
+ return TRUE;
+ }
+ else
+ {
+ if (gtk_css_parser_has_ident (parser, parser_values[i].name))
+ return TRUE;
+ }
}
return FALSE;
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c
index dd7a949b9f..ac0eab182a 100644
--- a/gtk/gtkcssimage.c
+++ b/gtk/gtkcssimage.c
@@ -509,7 +509,7 @@ gtk_css_image_get_parser_type (GtkCssParser *parser)
for (i = 0; i < G_N_ELEMENTS (image_types); i++)
{
- if (_gtk_css_parser_has_prefix (parser, image_types[i].prefix))
+ if (gtk_css_parser_has_function (parser, image_types[i].prefix))
return image_types[i].type_func ();
}
diff --git a/gtk/gtkcssnumbervalue.c b/gtk/gtkcssnumbervalue.c
index 24396fa29d..6b742c42e1 100644
--- a/gtk/gtkcssnumbervalue.c
+++ b/gtk/gtkcssnumbervalue.c
@@ -130,14 +130,14 @@ gboolean
gtk_css_number_value_can_parse (GtkCssParser *parser)
{
return _gtk_css_parser_has_number (parser)
- || _gtk_css_parser_has_prefix (parser, "calc");
+ || gtk_css_parser_has_function (parser, "calc");
}
GtkCssValue *
_gtk_css_number_value_parse (GtkCssParser *parser,
GtkCssNumberParseFlags flags)
{
- if (_gtk_css_parser_has_prefix (parser, "calc"))
+ if (gtk_css_parser_has_function (parser, "calc"))
return gtk_css_calc_value_parse (parser, flags);
return gtk_css_dimension_value_parse (parser, flags);
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index 66f0ad8ef2..c9412e26bf 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -90,15 +90,6 @@ _gtk_css_parser_free (GtkCssParser *parser)
g_slice_free (GtkCssParser, parser);
}
-gboolean
-_gtk_css_parser_has_prefix (GtkCssParser *parser,
- const char *prefix)
-{
- g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE);
-
- return g_ascii_strncasecmp (parser->data, prefix, strlen (prefix)) == 0;
-}
-
guint
_gtk_css_parser_get_line (GtkCssParser *parser)
{
@@ -634,6 +625,21 @@ gtk_css_parser_has_token (GtkCssParser *parser,
}
}
+gboolean
+gtk_css_parser_has_ident (GtkCssParser *parser,
+ const char *ident)
+{
+ gsize len;
+
+ g_return_val_if_fail (GTK_IS_CSS_PARSER (parser), FALSE);
+ g_return_val_if_fail (ident != NULL, FALSE);
+
+ len = strlen (ident);
+
+ return g_ascii_strncasecmp (parser->data, ident, len) == 0 &&
+ parser->data[len] != '(';
+}
+
gboolean
gtk_css_parser_has_function (GtkCssParser *parser,
const char *name)
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index 001d2060e5..1611dea07c 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -62,10 +62,10 @@ GFile * _gtk_css_parser_get_file (GtkCssParser *parser
GFile * _gtk_css_parser_get_file_for_path (GtkCssParser *parser,
const char *path);
-gboolean _gtk_css_parser_has_prefix (GtkCssParser *parser,
- const char *prefix);
gboolean gtk_css_parser_has_token (GtkCssParser *parser,
GtkCssTokenType token_type);
+gboolean gtk_css_parser_has_ident (GtkCssParser *parser,
+ const char *name);
gboolean gtk_css_parser_has_function (GtkCssParser *parser,
const char *name);
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index e653e69b98..6658f5eb33 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -1036,7 +1036,7 @@ parse_selector_pseudo_class_nth_child (GtkCssParser *parser,
}
a *= multiplier;
}
- else if (_gtk_css_parser_has_prefix (parser, "n"))
+ else if (gtk_css_parser_has_ident (parser, "n"))
{
a = multiplier;
}
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index 367c81f575..0668c9c6cc 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -261,7 +261,7 @@ parse_border_image (GtkCssShorthandProperty *shorthand,
do
{
if (values[0] == NULL &&
- (_gtk_css_parser_has_prefix (parser, "none") ||
+ (gtk_css_parser_has_ident (parser, "none") ||
_gtk_css_image_can_parse (parser)))
{
GtkCssImage *image;
@@ -494,7 +494,7 @@ parse_one_background (GtkCssShorthandProperty *shorthand,
{
/* the image part */
if (values[0] == NULL &&
- (_gtk_css_parser_has_prefix (parser, "none") ||
+ (gtk_css_parser_has_ident (parser, "none") ||
_gtk_css_image_can_parse (parser)))
{
GtkCssImage *image;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]