+ /* 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__);
+ }
+ }