After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 689035 - GMarkup utility for dealing with text
GMarkup utility for dealing with text
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-11-25 17:36 UTC by Allison Karlitskaya (desrt)
Modified: 2018-05-24 14:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gmarkup: add utility functions for text (14.62 KB, patch)
2013-02-04 00:20 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review

Description Allison Karlitskaya (desrt) 2012-11-25 17:36:59 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...
Comment 1 Allison Karlitskaya (desrt) 2013-02-04 00:20:31 UTC
Created attachment 235128 [details] [review]
gmarkup: add utility functions for text

WIP patch.
Comment 2 Matthias Clasen 2013-10-28 23:33:09 UTC
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.
Comment 3 Matthias Clasen 2013-10-28 23:36:01 UTC
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
Comment 4 GNOME Infrastructure Team 2018-05-24 14:52:02 UTC
-- 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.