From 29a16d7ae10ff54b5bdb2a64ecdbc7e6e26bb3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Tue, 6 May 2014 10:04:26 +0100 Subject: [PATCH] lib/mu-str.c: squash white space ctrl chars to spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When processing multiple lines for a subject line separated by TAB characters we don't want to eliminate the control character totally but replace it with a simple space. I've left the control handling as before for non-white space characters. Signed-off-by: Alex Bennée --- lib/mu-str.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/mu-str.c b/lib/mu-str.c index 11801be9..5c09a7b3 100644 --- a/lib/mu-str.c +++ b/lib/mu-str.c @@ -1056,15 +1056,19 @@ mu_str_remove_ctrl_in_place (char *str) if (!iscntrl(*cur)) continue; - /* control char detected... */ - gstr = g_string_sized_new (strlen (str)); - for (cur = str; *cur; ++cur) - if (!iscntrl (*cur)) - g_string_append_c (gstr, *cur); - memcpy (str, gstr->str, gstr->len); /* fits */ - g_string_free (gstr, TRUE); - - break; + if (isspace(*cur)) { + /* squash special white space into a simple space */ + *cur = ' '; + } else { + /* remove other control characters */ + gstr = g_string_sized_new (strlen (str)); + for (cur = str; *cur; ++cur) + if (!iscntrl (*cur)) + g_string_append_c (gstr, *cur); + memcpy (str, gstr->str, gstr->len); /* fits */ + g_string_free (gstr, TRUE); + break; + } } return str;