cssparser: Add gtk_css_parser_try_delim()

For parsing single code point delimiters. Also port calc() to use this.
This commit is contained in:
Benjamin Otte 2019-04-05 02:57:14 +02:00
parent 23080d47b5
commit 5f3e5a0406
4 changed files with 20 additions and 7 deletions

View File

@ -366,7 +366,7 @@ gtk_css_calc_value_parse_product (GtkCssParser *parser,
if (actual_flags != GTK_CSS_PARSE_NUMBER && !is_number (result)) if (actual_flags != GTK_CSS_PARSE_NUMBER && !is_number (result))
actual_flags = GTK_CSS_PARSE_NUMBER; 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); value = gtk_css_calc_value_parse_product (parser, actual_flags);
if (value == NULL) if (value == NULL)
@ -379,7 +379,7 @@ gtk_css_calc_value_parse_product (GtkCssParser *parser,
_gtk_css_value_unref (result); _gtk_css_value_unref (result);
result = temp; 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); value = gtk_css_calc_value_parse_product (parser, GTK_CSS_PARSE_NUMBER);
if (value == NULL) if (value == NULL)
@ -422,13 +422,13 @@ gtk_css_calc_value_parse_sum (GtkCssParser *parser,
{ {
GtkCssValue *next, *temp; 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); next = gtk_css_calc_value_parse_product (parser, flags);
if (next == NULL) if (next == NULL)
goto fail; 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); temp = gtk_css_calc_value_parse_product (parser, flags);
if (temp == NULL) if (temp == NULL)

View File

@ -320,6 +320,17 @@ gtk_css_parser_try_ident (GtkCssParser *parser,
return TRUE; 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 gboolean
gtk_css_parser_try_token (GtkCssParser *parser, gtk_css_parser_try_token (GtkCssParser *parser,
GtkCssTokenType type) GtkCssTokenType type)

View File

@ -79,6 +79,8 @@ gboolean gtk_css_parser_has_function (GtkCssParser *parser
*/ */
gboolean gtk_css_parser_try_ident (GtkCssParser *parser, gboolean gtk_css_parser_try_ident (GtkCssParser *parser,
const char *ident); const char *ident);
gboolean gtk_css_parser_try_delim (GtkCssParser *parser,
gunichar delim);
gboolean gtk_css_parser_try_at_keyword (GtkCssParser *parser, gboolean gtk_css_parser_try_at_keyword (GtkCssParser *parser,
const char *keyword); const char *keyword);
gboolean gtk_css_parser_try_token (GtkCssParser *parser, gboolean gtk_css_parser_try_token (GtkCssParser *parser,

View File

@ -155,7 +155,7 @@ parse_border_radius (GtkCssShorthandProperty *shorthand,
for (; i < 4; i++) for (; i < 4; i++)
x[i] = _gtk_css_value_ref (x[(i - 1) >> 1]); 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++) for (i = 0; i < 4; i++)
{ {
@ -293,7 +293,7 @@ parse_border_image (GtkCssShorthandProperty *shorthand,
if (values[1] == NULL) if (values[1] == NULL)
return FALSE; return FALSE;
if (_gtk_css_parser_try (parser, "/", TRUE)) if (gtk_css_parser_try_delim (parser, '/'))
{ {
values[2] = _gtk_css_border_value_parse (parser, values[2] = _gtk_css_border_value_parse (parser,
GTK_CSS_PARSE_PERCENT GTK_CSS_PARSE_PERCENT
@ -529,7 +529,7 @@ parse_one_background (GtkCssShorthandProperty *shorthand,
values[1] = value; values[1] = value;
value = NULL; value = NULL;
if (_gtk_css_parser_try (parser, "/", TRUE) && if (gtk_css_parser_try_delim (parser, '/') &&
(value = _gtk_css_bg_size_value_parse (parser))) (value = _gtk_css_bg_size_value_parse (parser)))
{ {
values[2] = value; values[2] = value;