* remove modest_text_utils_convert_to_pango, we have the
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Sat, 21 Apr 2007 18:27:59 +0000 (18:27 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Sat, 21 Apr 2007 18:27:59 +0000 (18:27 +0000)
g_markup_... functions in glib instead

pmo-trunk-r1628

src/modest-text-utils.c
src/modest-text-utils.h

index 6bc2283..e2dcf79 100644 (file)
@@ -273,97 +273,63 @@ modest_text_utils_remove_address (const gchar *address_list, const gchar *addres
 }
 
 
 }
 
 
-static gchar*
-modest_text_utils_convert_to_html_or_pango (const gchar *data, gboolean pango)
+gchar*
+modest_text_utils_convert_to_html (const gchar *data)
 {
        guint            i;
 {
        guint            i;
-       gboolean         first_space = TRUE;
+       gboolean        space_seen = FALSE;
        GString         *html;      
        gsize           len;
        GString         *html;      
        gsize           len;
-
+       
        if (!data)
                return NULL;
 
        len = strlen (data);
        html = g_string_sized_new (1.5 * len);  /* just a  guess... */
 
        if (!data)
                return NULL;
 
        len = strlen (data);
        html = g_string_sized_new (1.5 * len);  /* just a  guess... */
 
-       if (!pango)
-               g_string_append_printf (html,
-                                       "<html>"
-                                       "<head>"
-                                       "<meta http-equiv=\"content-type\""
-                                       " content=\"text/html; charset=utf8\">"
-                                       "</head>"
-                                       "<body><tt>");
+       g_string_append_printf (html,
+                               "<html><head>"
+                               "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf8\">"
+                               "</head>"
+                               "<body><tt>");
        
        /* replace with special html chars where needed*/
        for (i = 0; i != len; ++i)  {
        
        /* 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) {
                switch (kar) {
-                       
                case 0:  break; /* ignore embedded \0s */       
                case 0:  break; /* ignore embedded \0s */       
-               case '<'  : g_string_append   (html, "&lt;");   break;
-               case '>'  : g_string_append   (html, "&gt;");   break;
-               case '&'  : g_string_append   (html, "&amp;");  break;
-               case '\'' : g_string_append   (html, "&apos;"); break;
-               case '\n' : g_string_append   (html, "<br>\n");  break;
+               case '<'  : g_string_append (html, "&lt;");   break;
+               case '>'  : g_string_append (html, "&gt;");   break;
+               case '&'  : g_string_append (html, "&amp;");  break;
+               case '"'  : g_string_append (html, "&quot;");  break;
+               case '\'' : g_string_append (html, "&apos;"); break;
+               case '\n' : g_string_append (html, "<br>\n");  break;
+               case '\t' : g_string_append (html, "&nbsp;&nbsp;&nbsp; "); break; /* note the space at the end*/
+               case ' ':
+                       if (space_seen) { /* second space in a row */
+                               g_string_append (html, "&nbsp ");
+                               space_seen = FALSE;
+                       } else
+                               space_seen = TRUE;
+                       break;
                default:
                default:
-                       if (!pango && (kar==' '||kar=='\t')) {
-                               if (kar == ' ') {
-                                       g_string_append (html, first_space ? " " : "&nbsp;");
-                                       first_space = FALSE;
-                               } else /* kart == '\t' */
-                                       g_string_append (html, "&nbsp; &nbsp;&nbsp;");
-                       } 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);
                }
        }
                }
        }
-
-       if (!pango) {
-               g_string_append (html, "</tt></body></html>");
-               hyperlinkify_plain_text (html);
-       }
+       
+       g_string_append (html, "</tt></body></html>");
+       hyperlinkify_plain_text (html);
 
        return g_string_free (html, FALSE);
 }
 
 
 
        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)
 {
 GSList *
 modest_text_utils_split_addresses_list (const gchar *addresses)
 {
index 8dedca4..ffe623f 100644 (file)
@@ -147,18 +147,6 @@ void     modest_text_utils_address_range_at_position (const gchar *recipients_li
  */
 gchar*  modest_text_utils_convert_to_html (const gchar *txt);
 
  */
 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:
 
 /**
  * modest_text_utils_strftime: