[gtk+] Don't try to modify readonly strings
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Don't try to modify readonly strings
- Date: Wed, 9 Feb 2011 22:33:16 +0000 (UTC)
commit 3f1c95de8d411b956c6e51aa3bcc9baed1ab4558
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Feb 9 17:32:05 2011 -0500
Don't try to modify readonly strings
This was an oversight in the recent accel label improvement.
When we get an untranslated string back from gettext(), it is
not ok to replace '_' by ' ' in-place. Instead, do it while
appending to the GString.
https://bugzilla.gnome.org/show_bug.cgi?id=641912
gtk/gtkaccellabel.c | 44 ++++++++++++++++++++++----------------------
1 files changed, 22 insertions(+), 22 deletions(-)
---
diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c
index 0b0e1bc..e48933d 100644
--- a/gtk/gtkaccellabel.c
+++ b/gtk/gtkaccellabel.c
@@ -597,30 +597,34 @@ gtk_accel_label_get_string (GtkAccelLabel *accel_label)
}
/* Underscores in key names are better displayed as spaces
- * E.g., Page_Up should be "Page Up"
+ * E.g., Page_Up should be "Page Up".
+ *
+ * Some keynames also have prefixes that are not suitable
+ * for display, e.g XF86AudioMute, so strip those out, too.
+ *
+ * This function is only called on untranslated keynames,
+ * so no need to be UTF-8 safe.
*/
static void
-substitute_underscores (gchar *str)
+append_without_underscores (GString *s,
+ gchar *str)
{
- char *p;
+ gchar *p;
- for (p = str; *p; p++)
- if (*p == '_')
- *p = ' ';
-}
-
-/* Some keynames have prefixes that are not suitable
- * for display, e.g XF86AudioMute
- */
-static gchar *
-strip_prefix (gchar *str)
-{
if (g_str_has_prefix (str, "XF86"))
- return str + 4;
+ p = str + 4;
else if (g_str_has_prefix (str, "ISO_"))
- return str + 4;
+ p = str + 4;
+ else
+ p = str;
- return str;
+ for ( ; *p; p++)
+ {
+ if (*p == '_')
+ g_string_append_c (s, ' ');
+ else
+ g_string_append_c (s, *p);
+ }
}
/* On Mac, if the key has symbolic representation (e.g. arrow keys),
@@ -846,11 +850,7 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
const gchar *str;
str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp);
if (str == tmp)
- {
- substitute_underscores (tmp);
- tmp = strip_prefix (tmp);
- g_string_append (gstring, tmp);
- }
+ append_without_underscores (gstring, tmp);
else
g_string_append (gstring, str);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]