GNOME Bugzilla – Bug 689035
GMarkup utility for dealing with text
Last modified: 2018-05-24 14:52:02 UTC
It would be nice to have a GMarkup subparser designed for dealing with simple text sub-strings. The pattern that I find myself using is always the same: - create a GString in start_element(), making note of the value of optional "translatable" and "context" attribute on the opening tag - append to the string in text() - in end_element() do various things to translate the string - in text(), if we get any non-whitespace characters and the string is not set in the parser state, give an error We could make a really nice subparser for dealing with this: void g_markup_string_parser_start (GMarkupParseContext *context, gboolean translatable, const gchar *gettext_domain, const gchar *context); gchar * g_markup_string_parser_end (GMarkupParseContext *context); void g_markup_parser_reject_text (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error); The idea is that you would give 'g_markup_parser_reject_text' as the 'text' vfunc in your GMarkupParser struct. It would reject any non-whitespace text it encountered in the document (while not subparsing). Then the subparser would work by taking the translatable/gettext-domain/context strings from the context of the opening tag and collecting text, while rejecting nested tags. At the end, you get your already-translated string out of g_markup_string_parser_end(). Would be worth considering applying the GSettings schema whitespace handling rules here. I believe them to be quite sane for general-purpose use (in short: remove leading and trailing whitespace, collapsing all other whitespace except for double-newlines which are preserved as paragraph breaks). intltool knows about these conventions and it produces the normalised strings for the .po files...
Created attachment 235128 [details] [review] gmarkup: add utility functions for text WIP patch.
Review of attachment 235128 [details] [review]: ::: glib/gmarkup.c @@ +2986,3 @@ + * typedef struct + * { + * // For the file I try to avoid C99 comments in examples. @@ +3007,3 @@ + * element_stack = g_markup_parse_context_get_element_stack (context); + * container = element_stack->next ? element_stack->next->data : NULL; + * Could use g_markup_parse_context_get_element, and avoid the list juggling.
Review of attachment 235128 [details] [review]: ::: glib/gmarkup.c @@ +3095,3 @@ + * error + * }; + * ]| This is a long example. Might be nicer to go all the way, make this a complete program, and xinclude it from tests/ @@ +3217,3 @@ + + for (i = 0; i < text_len; i++) + if (!g_ascii_isspace (text[i])) Why ascii ? We should be prepared to meet arbitrary Unicode here. We should check what xml whitespace handling rules say about non-ascii whitespace
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/636.