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 119678 - GMarkup and printf
GMarkup and printf
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.2.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2003-08-11 23:26 UTC by Owen Taylor
Modified: 2011-02-18 16:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Implementation of the idea (5.40 KB, text/plain)
2003-08-11 23:29 UTC, Owen Taylor
Details

Description Owen Taylor 2003-08-11 23:26:41 UTC
It would be very nice to have a function that could
be used in situations like gtk_dialog_new_with_markup()
that automatically escaped all string and character
arguments with g_markup_escape_text()

The problem here is implementing it. Problems with
doing the printf first:

 * Hard to implement - we need to be able to do something
   with only the parts of the string that are printf
   output.

Problems with parsing the markup first, then doing
the printf.

 * What does Should %<b>s</b> work as a string format?
   What is the right result?
 * Should #x2f;s work as a string format?
 * Hard to implement; how do we know how to adjust
   the attrlist for the effects of the expansion.

A trick we can use to implement this described as follows:

Say, we have 

 printf ("Jane %s the %s\N", verb, noun);

If we compare the results of:

 printf ("%sX%sX", verb, noun);
 printf ("%sX%sY", verb, noun);

And we get:

 "ateXcakeX"
 "ateYcakeY"

then by finding the next position at which the two strings
vary we can determine that the two formatted segments
were "ate" and "cake". 

The attached patch implements this, using a heavily stripped
down form of gnulib's printf-parse.c to find the conversion
specifiers. It's not especially efficient way of doing
things but should be quite portable.

Perhaps g_markup_escaped_printf() / g_markup_escaped_printfv()
for names for the functions.

The patch could use some more tests and some comments, and
needs documentation.
Comment 1 Owen Taylor 2003-08-11 23:29:18 UTC
Created attachment 19131 [details]
Implementation of the idea
Comment 2 Owen Taylor 2003-09-12 00:18:54 UTC
Thu Sep 11 20:11:05 2003  Owen Taylor  <otaylor@redhat.com>
 
        * glib/gmarkup.c: Add g_markup_printf_escaped(),
        g_markup_vprintf_escaped().
 
        * tests/markup-escape-test.c (main): Test for
        g_markup_escape_text(), g_markup_printf_escaped().