[gtk/quartz-elide-underscores: 1/2] Bring back elide_underscores
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/quartz-elide-underscores: 1/2] Bring back elide_underscores
- Date: Mon, 24 May 2021 21:39:36 +0000 (UTC)
commit dab7ceaa249da360909a88d2fc3873ae8da7ce1f
Author: Matthias Clasen <mclasen redhat com>
Date: Mon May 24 17:37:05 2021 -0400
Bring back elide_underscores
This used to live in gtktoolbar.c, which is gone.
We still need it, so put it in gtkprivate.c.
gtk/gtkprivate.c | 43 +++++++++++++++++++++++++++++++++++++++++++
gtk/gtkprivate.h | 2 ++
2 files changed, 45 insertions(+)
---
diff --git a/gtk/gtkprivate.c b/gtk/gtkprivate.c
index ce7077e7c2..519d91f4a1 100644
--- a/gtk/gtkprivate.c
+++ b/gtk/gtkprivate.c
@@ -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;
+}
diff --git a/gtk/gtkprivate.h b/gtk/gtkprivate.h
index cd41e85b2c..ff3e188eef 100644
--- a/gtk/gtkprivate.h
+++ b/gtk/gtkprivate.h
@@ -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__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]