diff options
author | Alexander Larsson <alexl@redhat.com> | 2018-09-10 05:01:25 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2018-09-10 05:01:25 +0200 |
commit | a83c8705d1c940ee6110c31940b66a3579187253 (patch) | |
tree | a9e4d4e3b245fbb9d436ac1949027f610fcaaff6 | |
parent | a50ccb3c6c2f15aed2f189702b8faa49b96f9073 (diff) | |
download | glib-wip/alexl/gmarkup-record.tar.gz |
glib-compile-resources: Add xml-preparse convert optionwip/alexl/gmarkup-record
This uses g_markup_parse_context_record() and is useful to pre-parse
GtkBuilder files for faster parsing.
-rw-r--r-- | gio/glib-compile-resources.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c index 6ce5aec4a..ceab02082 100644 --- a/gio/glib-compile-resources.c +++ b/gio/glib-compile-resources.c @@ -220,6 +220,7 @@ end_element (GMarkupParseContext *context, gchar *key; FileData *data = NULL; char *tmp_file = NULL; + gboolean xml_preparse = FALSE; file = state->string->str; key = file; @@ -283,6 +284,8 @@ end_element (GMarkupParseContext *context, { if (!strcmp (options[i], "xml-stripblanks")) xml_stripblanks = TRUE; + else if (!strcmp (options[i], "xml-preparse")) + xml_preparse = TRUE; else if (!strcmp (options[i], "to-pixdata")) to_pixdata = TRUE; else if (!strcmp (options[i], "json-stripblanks")) @@ -465,6 +468,24 @@ end_element (GMarkupParseContext *context, /* Include zero termination in content_size for uncompressed files (but not in size) */ data->content_size = data->size + 1; + if (xml_preparse) + { + GBytes *preparsed = g_markup_parse_context_record (G_MARKUP_TREAT_CDATA_AS_TEXT, + data->content, data->size, &my_error); + if (preparsed == NULL) + { + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, + _("Error pre-parsing xml file %s: %s"), + real_file, my_error->message); + g_clear_error (&my_error); + goto cleanup; + } + + g_free (data->content); + data->content = g_bytes_unref_to_data (preparsed, &data->size); + data->content_size = data->size; + } + if (state->compressed) { GOutputStream *out = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); |