X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-text-utils.c;h=e2dcf7986c0a76f7b61cfd16cb8bb221893b2c61;hp=f411a1dd57eeb6dbe2c2b5dc5653ea7926e6dedf;hb=741cdadffee332ebf732d018def442338325c233;hpb=8877001a218f1dfd23a5ea9a98532144a4fffe93 diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index f411a1d..e2dcf79 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -204,15 +204,12 @@ gsize modest_text_utils_strftime(char *s, gsize max, const char *fmt, time_t timet) { struct tm tm; -/* static GDate date; */ /* does not work on old maemo glib: * g_date_set_time_t (&date, timet); */ -/* g_date_set_time (&date, (GTime) timet); */ localtime_r (&timet, &tm); -/* return g_date_strftime (s, max, fmt, (const GDate*) &date); */ return strftime(s, max, fmt, &tm); } @@ -275,58 +272,54 @@ modest_text_utils_remove_address (const gchar *address_list, const gchar *addres return result; } + gchar* modest_text_utils_convert_to_html (const gchar *data) { guint i; - gboolean first_space = TRUE; + gboolean space_seen = FALSE; GString *html; gsize len; - + if (!data) return NULL; len = strlen (data); - html = g_string_sized_new (len + 100); /* just a guess... */ - + html = g_string_sized_new (1.5 * len); /* just a guess... */ + g_string_append_printf (html, - "" - "" - "" + "" + "" "" ""); /* replace with special html chars where needed*/ for (i = 0; i != len; ++i) { - char kar = data[i]; + char kar = data[i]; + + if (space_seen && kar != ' ') { + g_string_append_c (html, ' '); + space_seen = FALSE; + } + switch (kar) { - case 0: break; /* ignore embedded \0s */ - case '<' : g_string_append (html, "<"); break; - case '>' : g_string_append (html, ">"); break; - case '&' : g_string_append (html, """); break; - case '\n': g_string_append (html, "
\n"); break; + case '<' : g_string_append (html, "<"); break; + case '>' : g_string_append (html, ">"); break; + case '&' : g_string_append (html, "&"); break; + case '"' : g_string_append (html, """); break; + case '\'' : g_string_append (html, "'"); break; + case '\n' : g_string_append (html, "
\n"); break; + case '\t' : g_string_append (html, "    "); break; /* note the space at the end*/ + case ' ': + if (space_seen) { /* second space in a row */ + g_string_append (html, "  "); + space_seen = FALSE; + } else + space_seen = TRUE; + break; default: - if (kar == ' ') { - g_string_append (html, first_space ? " " : " "); - first_space = FALSE; - } else if (kar == '\t') - g_string_append (html, "    "); - else { - int charnum = 0; - first_space = TRUE; - /* optimization trick: accumulate 'normal' chars, then copy */ - do { - kar = data [++charnum + i]; - - } while ((i + charnum < len) && - (kar > '>' || (kar != '<' && kar != '>' - && kar != '&' && kar != ' ' - && kar != '\n' && kar != '\t'))); - g_string_append_len (html, &data[i], charnum); - i += (charnum - 1); - } + g_string_append_c (html, kar); } } @@ -336,6 +329,7 @@ modest_text_utils_convert_to_html (const gchar *data) return g_string_free (html, FALSE); } + GSList * modest_text_utils_split_addresses_list (const gchar *addresses) {