Revert fix for modest_text_utils_convert_buffer_to_html_start()
authorAlberto Garcia <agarcia@igalia.com>
Wed, 13 Feb 2008 12:32:10 +0000 (12:32 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Wed, 13 Feb 2008 12:32:10 +0000 (12:32 +0000)
in r4166 and apply a more optimal one instead

pmo-trunk-r4169

src/modest-text-utils.c

index 38f55ad..f2ca840 100644 (file)
@@ -391,7 +391,7 @@ modest_text_utils_remove_duplicate_addresses (const gchar *address_list)
 static void
 modest_text_utils_convert_buffer_to_html_start (GString *html, const gchar *data, gssize n)
 {
-       guint           i = 0;
+       guint           i;
        gboolean        space_seen = FALSE;
        guint           break_dist = 0; /* distance since last break point */
 
@@ -399,8 +399,8 @@ modest_text_utils_convert_buffer_to_html_start (GString *html, const gchar *data
                n = strlen (data);
 
        /* replace with special html chars where needed*/
-       while (i != n) {
-               char kar = data[i];
+       for (i = 0; i != n; ++i)  {
+               guchar kar = data[i];
                
                if (space_seen && kar != ' ') {
                        g_string_append_c (html, ' ');
@@ -410,8 +410,10 @@ modest_text_utils_convert_buffer_to_html_start (GString *html, const gchar *data
                /* we artificially insert a breakpoint (newline)
                 * after 256, to make sure our lines are not so long
                 * they will DOS the regexping later
+                * Also, check that kar is ASCII to make sure that we
+                * don't break a UTF8 char in two
                 */
-               if (++break_dist == 256) {
+               if (++break_dist >= 256 && kar < 127) {
                        g_string_append_c (html, '\n');
                        break_dist = 0;
                }
@@ -443,25 +445,8 @@ modest_text_utils_convert_buffer_to_html_start (GString *html, const gchar *data
                                space_seen = TRUE;
                        break;
                default:
-                       /* Optimization to copy single ascii
-                        * characters faster */
-                       if (kar > 31 && kar < 127) {
-                               g_string_append_c (html, kar);
-                       } else {
-                               /* Important: copy full UTF-8 characters,
-                                * don't copy them byte by byte */
-                               gunichar c = g_utf8_get_char_validated (data+i, -1);
-                               if (c != (gunichar) -1 && c != (gunichar) -2) {
-                                       const gchar *copyfrom = data + i;
-                                       int len = g_utf8_next_char(copyfrom) - copyfrom;
-                                       g_string_append_len (html, copyfrom, len);
-                                       i += len - 1;
-                               } else {
-                                       g_warning ("%s: non-UTF8 byte found, skipping", __FUNCTION__);
-                               }
-                       }
+                       g_string_append_c (html, kar);
                }
-               i++;
        }
 }