From: Christian Dywan Date: Fri, 17 Jul 2009 19:29:57 +0000 (+0200) Subject: Add katze_strip_mnemonics (formerly known as elide_underscores) X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25da4122150ac33df292525dd2c3add1be07a180;p=midori Add katze_strip_mnemonics (formerly known as elide_underscores) --- diff --git a/katze/katze-utils.c b/katze/katze-utils.c index 42e87031..253d8955 100644 --- a/katze/katze-utils.c +++ b/katze/katze-utils.c @@ -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 diff --git a/katze/katze-utils.h b/katze/katze-utils.h index 77c104e4..5d237d16 100644 --- a/katze/katze-utils.h +++ b/katze/katze-utils.h @@ -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);