Add katze_strip_mnemonics (formerly known as elide_underscores)

This commit is contained in:
Christian Dywan 2009-07-17 21:29:57 +02:00
parent 35f11238a4
commit 25da412215
2 changed files with 61 additions and 0 deletions

View file

@ -624,6 +624,64 @@ katze_tree_view_get_selected_iter (GtkTreeView* treeview,
return FALSE;
}
/**
* katze_strip_mnemonics:
* @original: a string with mnemonics
*
* Parses the given string for mnemonics in the form
* "B_utton" or "Button (_U)" and returns a string
* without any mnemonics.
*
* Return value: a newly allocated string without mnemonics
*
* Since: 0.1.8
**/
gchar*
katze_strip_mnemonics (const gchar* original)
{
/* A copy of _gtk_toolbar_elide_underscores
Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
Copied from GTK+ 2.17.1 */
gchar *q, *result;
const gchar *p, *end;
gsize len;
gboolean last_underscore;
if (!original)
return NULL;
len = strlen (original);
q = result = g_malloc (len + 1);
last_underscore = FALSE;
end = original + len;
for (p = original; p < end; p++)
{
if (!last_underscore && *p == '_')
last_underscore = TRUE;
else
{
last_underscore = FALSE;
if (original + 2 <= p && p + 1 <= end &&
p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
{
q--;
*q = '\0';
p++;
}
else
*q++ = *p;
}
}
if (last_underscore)
*q++ = '_';
*q = '\0';
return result;
}
/**
* katze_object_has_property:
* @object: a #GObject

View file

@ -106,6 +106,9 @@ katze_tree_view_get_selected_iter (GtkTreeView* treeview,
GtkTreeModel** model,
GtkTreeIter* iter);
gchar*
katze_strip_mnemonics (const gchar* original);
gboolean
katze_object_has_property (gpointer object,
const gchar* property);