Bring back elide_underscores

This used to live in gtktoolbar.c, which is gone.
We still need it, so put it in gtkprivate.c.
This commit is contained in:
Matthias Clasen 2021-05-24 17:37:05 -04:00
parent b05f3f5614
commit dab7ceaa24
2 changed files with 45 additions and 0 deletions

View File

@ -266,3 +266,46 @@ gtk_get_portal_session_path (GDBusConnection *connection,
{
return get_portal_path (connection, "session", token);
}
char *
_gtk_elide_underscores (const char *original)
{
char *q, *result;
const char *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;
}

View File

@ -144,6 +144,8 @@ GBytes *get_emoji_data (void);
#endif /* G_ENABLE_DEBUG */
char * _gtk_elide_underscores (const char *original);
G_END_DECLS
#endif /* __GTK_PRIVATE_H__ */