From: Dirk-Jan C. Binnema Date: Fri, 20 Apr 2007 18:56:39 +0000 (+0000) Subject: * replace the _pango functions with modest_text_utils_convert_to_pango, X-Git-Tag: git_migration_finished~3836 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=c3c7de8afda2eb9cdb514fb517c6f188c8054e06 * replace the _pango functions with modest_text_utils_convert_to_pango, which require fewer string copies. pmo-trunk-r1621 --- diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 9b0cef4..6bc2283 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -272,8 +272,9 @@ modest_text_utils_remove_address (const gchar *address_list, const gchar *addres return result; } -gchar* -modest_text_utils_convert_to_html (const gchar *data) + +static gchar* +modest_text_utils_convert_to_html_or_pango (const gchar *data, gboolean pango) { guint i; gboolean first_space = TRUE; @@ -284,15 +285,16 @@ modest_text_utils_convert_to_html (const gchar *data) return NULL; len = strlen (data); - html = g_string_sized_new (len + 100); /* just a guess... */ - - g_string_append_printf (html, - "" - "" - "" - "" - ""); + html = g_string_sized_new (1.5 * len); /* just a guess... */ + + if (!pango) + g_string_append_printf (html, + "" + "" + "" + "" + ""); /* replace with special html chars where needed*/ for (i = 0; i != len; ++i) { @@ -300,17 +302,19 @@ modest_text_utils_convert_to_html (const gchar *data) 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 '\n' : g_string_append (html, "
\n"); break; default: - if (kar == ' ') { - g_string_append (html, first_space ? " " : " "); - first_space = FALSE; - } else if (kar == '\t') - g_string_append (html, "    "); - else { + if (!pango && (kar==' '||kar=='\t')) { + if (kar == ' ') { + g_string_append (html, first_space ? " " : " "); + first_space = FALSE; + } else /* kart == '\t' */ + g_string_append (html, "    "); + } else { int charnum = 0; first_space = TRUE; /* optimization trick: accumulate 'normal' chars, then copy */ @@ -326,13 +330,40 @@ modest_text_utils_convert_to_html (const gchar *data) } } } - - g_string_append (html, "
"); - hyperlinkify_plain_text (html); + + if (!pango) { + g_string_append (html, "
"); + hyperlinkify_plain_text (html); + } return g_string_free (html, FALSE); } + +gchar* +modest_text_utils_convert_to_html (const gchar *data) +{ + return modest_text_utils_convert_to_html_or_pango (data, FALSE); +} + + +gchar* +modest_text_utils_convert_to_pango (const gchar *data) +{ + /* FIXME: + * in many cases, it might not be needed to do anything, so + * we can simply scan the str for the special characters and + * if there are none, just return g_strdup (data). + * + * we could even get rid of the strdup there, and notify + * the caller that the string did not change -- however, + * that would complicate matters a bit on the caller side + */ + return modest_text_utils_convert_to_html_or_pango (data, TRUE); +} + + + GSList * modest_text_utils_split_addresses_list (const gchar *addresses) { diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 18dea34..8dedca4 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -139,7 +139,7 @@ void modest_text_utils_address_range_at_position (const gchar *recipients_li /** * modest_text_utils_convert_to_html: - * @txt: a string which contains the message to quote + * @txt: a string * * convert plain text (utf8) into html * @@ -147,6 +147,18 @@ void modest_text_utils_address_range_at_position (const gchar *recipients_li */ gchar* modest_text_utils_convert_to_html (const gchar *txt); +/** + * modest_text_utils_convert_to_pango: + * @txt: a string + * + * convert plain text (utf8) into pango-escaped text + * + * Returns: a newly allocated string containing the html + */ +gchar* modest_text_utils_convert_to_pango (const gchar *txt); + + + /** * modest_text_utils_strftime: diff --git a/src/widgets/modest-header-view-render.c b/src/widgets/modest-header-view-render.c index c0177da..b1c1daa 100644 --- a/src/widgets/modest-header-view-render.c +++ b/src/widgets/modest-header-view-render.c @@ -35,7 +35,7 @@ #include #include - +#if 0 static gchar * _pango_replace_string (const gchar *string, const gchar *in, @@ -102,6 +102,7 @@ _pango_parse_string (const gchar *string) return parsed_string; } +#endif static GdkPixbuf* get_pixbuf_for_flag (TnyHeaderFlags flag) @@ -374,8 +375,10 @@ _modest_header_view_compact_header_cell_data (GtkTreeViewColumn *column, GtkCe /* Escape special characteres to allow pango makup`*/ display_address = modest_text_utils_get_display_address (address); - parsed_address = _pango_parse_string (display_address); - parsed_subject = _pango_parse_string (subject); + parsed_address = modest_text_utils_convert_to_pango (display_address); + //_pango_parse_string (display_address); + parsed_subject = modest_text_utils_convert_to_pango (subject); + //_pango_parse_string (subject); header = g_strdup_printf ("%s\n%s", parsed_subject,