[Xfce4-commits] [apps/xfce4-taskmanager] 01/01: Better utf-8 normalization (bug 14172)

noreply at xfce.org noreply at xfce.org
Thu Aug 2 08:49:00 CEST 2018


This is an automated email from the git hooks/post-receive script.

l   a   n   d   r   y       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-taskmanager.

commit b89684865d88bbb8399f70387cae9e8ae17d64d9
Author: rim <rozhuk.im at gmail.com>
Date:   Sun Jul 29 09:22:48 2018 +0300

    Better utf-8 normalization (bug 14172)
---
 src/task-manager.c | 47 ++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 7 deletions(-)

diff --git a/src/task-manager.c b/src/task-manager.c
index 93f9122..8188de6 100644
--- a/src/task-manager.c
+++ b/src/task-manager.c
@@ -22,6 +22,7 @@
 #include <glib-object.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#include <gmodule.h>
 
 #include "task-manager.h"
 #ifdef HAVE_WNCK
@@ -125,12 +126,44 @@ setting_changed (GObject *object, GParamSpec *pspec __unused, XtmTaskManager *ma
 static gchar *
 pretty_cmdline (gchar *cmdline, gchar *comm)
 {
-	/* Use the printable range of 0x20-0x7E */
-	const gchar *valid_chars = " !\"#$%&'()*+,-./0123456789:;<=>?@"
-				   "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`"
-				   "abcdefghijklmnopqrstuvwxyz{|}~";
-	gchar *text = g_strstrip (g_strcanon (g_strdup (cmdline), valid_chars, ' '));
-	gsize text_size = (gsize)strlen (text);
+	gunichar c;
+	gchar *ch, *text_max, *text = g_strstrip (g_strdup (cmdline));
+	gsize csize, text_size = (gsize)strlen (text);
+
+	/* UTF-8 normalize. */
+	do {
+		for (ch = text, text_max = (text + text_size);
+		     text_max > ch;
+		     text_max = (text + text_size), ch = g_utf8_next_char(ch)) {
+			c = g_utf8_get_char_validated(ch, -1); /* If use (text_max - ch) - result is worse. */
+			if ((gunichar)-2 == c) {
+				text_size = (gsize)(ch - text);
+				(*ch) = 0;
+				break;
+			}
+			if ((gunichar)-1 == c) {
+				(*ch) = ' ';
+				continue;
+			}
+			csize = (gsize)g_unichar_to_utf8(c, NULL);
+
+			if (!g_unichar_isdefined(c) ||
+			    !g_unichar_isprint(c) ||
+			    (g_unichar_isspace(c) && (1 != csize || (' ' != (*ch) && '	' != (*ch)))) ||
+			    g_unichar_ismark(c) ||
+			    g_unichar_istitle(c) ||
+			    g_unichar_iswide(c) ||
+			    g_unichar_iszerowidth(c) ||
+			    g_unichar_iscntrl(c)) {
+				if (text_max < (ch + csize))
+					break;
+				memmove(ch, (ch + csize), (gsize)(text_max - (ch + csize)));
+				text_size -= csize;
+			}
+		}
+		text[text_size] = 0;
+	} while (!g_utf8_validate(text, (gssize)text_size, NULL));
+
 	if (!full_cmdline && text_size > 3)
 	{
 		/* Shorten full path to commands and wine applications */
@@ -139,7 +172,7 @@ pretty_cmdline (gchar *cmdline, gchar *comm)
 			gchar *p = g_strstr_len (text, (gssize)text_size, comm);
 			if (p != NULL)
 			{
-				g_strlcpy (text, p, text_size);
+				memmove (text, p, text_size);
 			}
 		}
 	}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list