* Added some missing includes
[modest] / src / modest-text-utils.c
index 9b0cef4..243ede3 100644 (file)
@@ -272,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,
-                               "<html>"
-                               "<head>"
-                               "<meta http-equiv=\"content-type\""
-                               " content=\"text/html; charset=utf8\">"
+                               "<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)  {
-               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, "&lt;"); break;
-               case '>' : g_string_append   (html, "&gt;"); break;
-               case '&' : g_string_append   (html, "&quot;"); 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:
-                       if (kar == ' ') {
-                               g_string_append (html, first_space ? " " : "&nbsp;");
-                               first_space = FALSE;
-                       } else  if (kar == '\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);
                }
        }
        
@@ -333,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)
 {
@@ -860,6 +857,8 @@ modest_text_utils_get_display_date (time_t date)
 
        modest_text_utils_strftime (date_buf, BUF_SIZE, "%d/%m/%Y", date);
        modest_text_utils_strftime (now_buf,  BUF_SIZE, "%d/%m/%Y",  now); /* today */
+/*     modest_text_utils_strftime (date_buf, BUF_SIZE, "%x", date); */
+/*     modest_text_utils_strftime (now_buf,  BUF_SIZE, "%x",  now); /\* today *\/ */
        
        /* if this is today, get the time instead of the date */
        if (strcmp (date_buf, now_buf) == 0)