[pango/newer-json-parser] Make an error-setting variant of select_string
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/newer-json-parser] Make an error-setting variant of select_string
- Date: Thu, 9 Dec 2021 14:25:27 +0000 (UTC)
commit b0810075bd571dade040f37b5ba7bf6ba12e2cbb
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Dec 9 09:23:51 2021 -0500
Make an error-setting variant of select_string
pango/serializer.c | 63 ++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 19 deletions(-)
---
diff --git a/pango/serializer.c b/pango/serializer.c
index 05ade546..a95da666 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -837,6 +837,31 @@ gstring_write (GtkJsonPrinter *printer,
/* }}} */
/* {{{ Deserialization */
+static int
+parser_select_string (GtkJsonParser *parser,
+ const char **options)
+{
+ int value;
+
+ value = gtk_json_parser_select_string (parser, options);
+ if (value == -1)
+ {
+ char *str = gtk_json_parser_get_string (parser);
+ char *opts = g_strjoinv (", ", (char **)options);
+
+ gtk_json_parser_value_error (parser,
+ "Failed to parse string: %s, valid options are: %s",
+ str, opts);
+
+ g_free (opts);
+ g_free (str);
+
+ value = 0;
+ }
+
+ return value;
+}
+
static PangoFontDescription *
parser_get_font_description (GtkJsonParser *parser)
{
@@ -899,22 +924,22 @@ attr_for_type (GtkJsonParser *parser,
break;
case PANGO_ATTR_STYLE:
- attr = pango_attr_style_new ((PangoStyle) gtk_json_parser_select_string (parser, style_names));
+ attr = pango_attr_style_new ((PangoStyle) parser_select_string (parser, style_names));
break;
case PANGO_ATTR_WEIGHT:
if (gtk_json_parser_get_node (parser) == GTK_JSON_STRING)
- attr = pango_attr_weight_new (get_weight (gtk_json_parser_select_string (parser, weight_names)));
+ attr = pango_attr_weight_new (get_weight (parser_select_string (parser, weight_names)));
else
attr = pango_attr_weight_new ((int) gtk_json_parser_get_int (parser));
break;
case PANGO_ATTR_VARIANT:
- attr = pango_attr_variant_new ((PangoVariant) gtk_json_parser_select_string (parser, variant_names));
+ attr = pango_attr_variant_new ((PangoVariant) parser_select_string (parser, variant_names));
break;
case PANGO_ATTR_STRETCH:
- attr = pango_attr_stretch_new ((PangoStretch) gtk_json_parser_select_string (parser, stretch_names));
+ attr = pango_attr_stretch_new ((PangoStretch) parser_select_string (parser, stretch_names));
break;
case PANGO_ATTR_SIZE:
@@ -938,7 +963,7 @@ attr_for_type (GtkJsonParser *parser,
break;
case PANGO_ATTR_UNDERLINE:
- attr = pango_attr_underline_new ((PangoUnderline) gtk_json_parser_select_string (parser,
underline_names));
+ attr = pango_attr_underline_new ((PangoUnderline) parser_select_string (parser, underline_names));
break;
case PANGO_ATTR_STRIKETHROUGH:
@@ -981,11 +1006,11 @@ attr_for_type (GtkJsonParser *parser,
break;
case PANGO_ATTR_GRAVITY:
- attr = pango_attr_gravity_new ((PangoGravity) gtk_json_parser_select_string (parser, gravity_names));
+ attr = pango_attr_gravity_new ((PangoGravity) parser_select_string (parser, gravity_names));
break;
case PANGO_ATTR_GRAVITY_HINT:
- attr = pango_attr_gravity_hint_new ((PangoGravityHint) gtk_json_parser_select_string (parser,
gravity_hint_names));
+ attr = pango_attr_gravity_hint_new ((PangoGravityHint) parser_select_string (parser,
gravity_hint_names));
break;
case PANGO_ATTR_FONT_FEATURES:
@@ -1015,7 +1040,7 @@ attr_for_type (GtkJsonParser *parser,
break;
case PANGO_ATTR_OVERLINE:
- attr = pango_attr_overline_new ((PangoOverline) gtk_json_parser_select_string (parser,
overline_names));
+ attr = pango_attr_overline_new ((PangoOverline) parser_select_string (parser, overline_names));
break;
case PANGO_ATTR_OVERLINE_COLOR:
@@ -1032,7 +1057,7 @@ attr_for_type (GtkJsonParser *parser,
break;
case PANGO_ATTR_TEXT_TRANSFORM:
- attr = pango_attr_text_transform_new ((PangoTextTransform) gtk_json_parser_select_string (parser,
text_transform_names));
+ attr = pango_attr_text_transform_new ((PangoTextTransform) parser_select_string (parser,
text_transform_names));
break;
case PANGO_ATTR_WORD:
@@ -1044,11 +1069,11 @@ attr_for_type (GtkJsonParser *parser,
break;
case PANGO_ATTR_BASELINE_SHIFT:
- attr = pango_attr_baseline_shift_new (gtk_json_parser_select_string (parser, baseline_shift_names));
+ attr = pango_attr_baseline_shift_new (parser_select_string (parser, baseline_shift_names));
break;
case PANGO_ATTR_FONT_SCALE:
- attr = pango_attr_font_scale_new ((PangoFontScale) gtk_json_parser_select_string (parser,
font_scale_names));
+ attr = pango_attr_font_scale_new ((PangoFontScale) parser_select_string (parser, font_scale_names));
break;
}
@@ -1096,7 +1121,7 @@ json_to_attribute (GtkJsonParser *parser)
break;
case ATTR_TYPE:
- type = gtk_json_parser_select_string (parser, attr_type_names);
+ type = parser_select_string (parser, attr_type_names);
break;
case ATTR_VALUE:
@@ -1175,7 +1200,7 @@ json_parser_fill_tabs (GtkJsonParser *parser,
break;
case TAB_ALIGNMENT:
- align = (PangoTabAlign) gtk_json_parser_select_string (parser, tab_align_names);
+ align = (PangoTabAlign) parser_select_string (parser, tab_align_names);
break;
case TAB_DECIMAL_POINT:
@@ -1289,15 +1314,15 @@ json_parser_fill_context (GtkJsonParser *parser,
break;
case CONTEXT_BASE_GRAVITY:
- pango_context_set_base_gravity (context, (PangoGravity) gtk_json_parser_select_string (parser,
gravity_names));
+ pango_context_set_base_gravity (context, (PangoGravity) parser_select_string (parser,
gravity_names));
break;
case CONTEXT_GRAVITY_HINT:
- pango_context_set_gravity_hint (context, (PangoGravityHint) gtk_json_parser_select_string (parser,
gravity_hint_names));
+ pango_context_set_gravity_hint (context, (PangoGravityHint) parser_select_string (parser,
gravity_hint_names));
break;
case CONTEXT_BASE_DIR:
- pango_context_set_base_dir (context, (PangoDirection) gtk_json_parser_select_string (parser,
direction_names));
+ pango_context_set_base_dir (context, (PangoDirection) parser_select_string (parser,
direction_names));
break;
case CONTEXT_ROUND_GLYPH_POSITIONS:
@@ -1452,15 +1477,15 @@ json_parser_fill_layout (GtkJsonParser *parser,
break;
case LAYOUT_ALIGNMENT:
- pango_layout_set_alignment (layout, (PangoAlignment) gtk_json_parser_select_member (parser,
alignment_names));
+ pango_layout_set_alignment (layout, (PangoAlignment) parser_select_string (parser,
alignment_names));
break;
case LAYOUT_WRAP:
- pango_layout_set_wrap (layout, (PangoWrapMode) gtk_json_parser_select_member (parser, wrap_names));
+ pango_layout_set_wrap (layout, (PangoWrapMode) parser_select_string (parser, wrap_names));
break;
case LAYOUT_ELLIPSIZE:
- pango_layout_set_ellipsize (layout, (PangoEllipsizeMode) gtk_json_parser_select_member (parser,
ellipsize_names));
+ pango_layout_set_ellipsize (layout, (PangoEllipsizeMode) parser_select_string (parser,
ellipsize_names));
break;
case LAYOUT_WIDTH:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]