Lines 1-84
Link Here
|
1 |
From b89684865d88bbb8399f70387cae9e8ae17d64d9 Mon Sep 17 00:00:00 2001 |
|
|
2 |
From: rim <rozhuk.im@gmail.com> |
3 |
Date: Sun, 29 Jul 2018 09:22:48 +0300 |
4 |
Subject: Better utf-8 normalization (bug 14172) |
5 |
|
6 |
--- |
7 |
src/task-manager.c | 47 ++++++++++++++++++++++++++++++++++++++++------- |
8 |
1 file changed, 40 insertions(+), 7 deletions(-) |
9 |
|
10 |
diff --git a/src/task-manager.c b/src/task-manager.c |
11 |
index 93f9122..8188de6 100644 |
12 |
--- src/task-manager.c |
13 |
+++ src/task-manager.c |
14 |
@@ -22,6 +22,7 @@ |
15 |
#include <glib-object.h> |
16 |
#include <glib/gi18n.h> |
17 |
#include <gtk/gtk.h> |
18 |
+#include <gmodule.h> |
19 |
|
20 |
#include "task-manager.h" |
21 |
#ifdef HAVE_WNCK |
22 |
@@ -125,12 +126,44 @@ setting_changed (GObject *object, GParamSpec *pspec __unused, XtmTaskManager *ma |
23 |
static gchar * |
24 |
pretty_cmdline (gchar *cmdline, gchar *comm) |
25 |
{ |
26 |
- /* Use the printable range of 0x20-0x7E */ |
27 |
- const gchar *valid_chars = " !\"#$%&'()*+,-./0123456789:;<=>?@" |
28 |
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" |
29 |
- "abcdefghijklmnopqrstuvwxyz{|}~"; |
30 |
- gchar *text = g_strstrip (g_strcanon (g_strdup (cmdline), valid_chars, ' ')); |
31 |
- gsize text_size = (gsize)strlen (text); |
32 |
+ gunichar c; |
33 |
+ gchar *ch, *text_max, *text = g_strstrip (g_strdup (cmdline)); |
34 |
+ gsize csize, text_size = (gsize)strlen (text); |
35 |
+ |
36 |
+ /* UTF-8 normalize. */ |
37 |
+ do { |
38 |
+ for (ch = text, text_max = (text + text_size); |
39 |
+ text_max > ch; |
40 |
+ text_max = (text + text_size), ch = g_utf8_next_char(ch)) { |
41 |
+ c = g_utf8_get_char_validated(ch, -1); /* If use (text_max - ch) - result is worse. */ |
42 |
+ if ((gunichar)-2 == c) { |
43 |
+ text_size = (gsize)(ch - text); |
44 |
+ (*ch) = 0; |
45 |
+ break; |
46 |
+ } |
47 |
+ if ((gunichar)-1 == c) { |
48 |
+ (*ch) = ' '; |
49 |
+ continue; |
50 |
+ } |
51 |
+ csize = (gsize)g_unichar_to_utf8(c, NULL); |
52 |
+ |
53 |
+ if (!g_unichar_isdefined(c) || |
54 |
+ !g_unichar_isprint(c) || |
55 |
+ (g_unichar_isspace(c) && (1 != csize || (' ' != (*ch) && ' ' != (*ch)))) || |
56 |
+ g_unichar_ismark(c) || |
57 |
+ g_unichar_istitle(c) || |
58 |
+ g_unichar_iswide(c) || |
59 |
+ g_unichar_iszerowidth(c) || |
60 |
+ g_unichar_iscntrl(c)) { |
61 |
+ if (text_max < (ch + csize)) |
62 |
+ break; |
63 |
+ memmove(ch, (ch + csize), (gsize)(text_max - (ch + csize))); |
64 |
+ text_size -= csize; |
65 |
+ } |
66 |
+ } |
67 |
+ text[text_size] = 0; |
68 |
+ } while (!g_utf8_validate(text, (gssize)text_size, NULL)); |
69 |
+ |
70 |
if (!full_cmdline && text_size > 3) |
71 |
{ |
72 |
/* Shorten full path to commands and wine applications */ |
73 |
@@ -139,7 +172,7 @@ pretty_cmdline (gchar *cmdline, gchar *comm) |
74 |
gchar *p = g_strstr_len (text, (gssize)text_size, comm); |
75 |
if (p != NULL) |
76 |
{ |
77 |
- g_strlcpy (text, p, text_size); |
78 |
+ memmove (text, p, text_size); |
79 |
} |
80 |
} |
81 |
} |
82 |
-- |
83 |
cgit v1.2.1 |
84 |
|