gtk_message_dialog_new_with_markup() revisited



After an IRC discussion with Kris, Noah and Anders yesterday,
I started thinking again about the question of making:

 new_with_markup (..., "My name is <i>%s</i>", name);

do the appropriate escaping automatically. (The discussion
started by discussing adding similar functions to set the 
text/markup of a label from a format string.)

After a few false starts, I came up with a method of 
implementing a g_markup_escaped_printf() - see:

 http://bugzilla.gnome.org/show_bug.cgi?id=119678 

For details and an implementation. To quote the section of the bug
report describing the basic approach:

 Say, we have 

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

 If we compare the results of:

   printf ("%sX%sX", verb, noun);
   printf ("%YX%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 question is whether we should make this addition to GLib and
switch new_with_markup() over before we release 2.4. We can't
do it afterwards.

Advantages:

 - We remove a trap that people are going to get wrong a
   fair bit of the time.
 - We reduce code size and make things easier.

Disadvantages: 
  
 - The implementation is rather inefficient, though it shouldn't
   matter much for most uses.
 - Perhaps a bit too magic
 - You might sometimes actually want markup in string
   arguments.
 - If you have a preexisting string with markup, you can't
   set it as the text of a message dialog by doing:

    new_with_markup ("%s", string);

   any more. We might need to add gtk_message_dialog_set_markup()
   to get around this problem.

What do people think?
					Owen





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]