diff options
author | Not Zed <NotZed@Ximian.com> | 2003-01-13 13:46:35 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2003-01-13 13:46:35 +0800 |
commit | 9b60cad3dc13970bb0b4562cf4f9b38f3edc46db (patch) | |
tree | b5f767bf7c76558d6728f2db3a5c9c3869ace389 /camel/camel-mime-filter-tohtml.c | |
parent | 969b2c6b650ed31a1accd44eda629c17c1b5ce8b (diff) | |
download | gsoc2013-evolution-9b60cad3dc13970bb0b4562cf4f9b38f3edc46db.tar gsoc2013-evolution-9b60cad3dc13970bb0b4562cf4f9b38f3edc46db.tar.gz gsoc2013-evolution-9b60cad3dc13970bb0b4562cf4f9b38f3edc46db.tar.bz2 gsoc2013-evolution-9b60cad3dc13970bb0b4562cf4f9b38f3edc46db.tar.lz gsoc2013-evolution-9b60cad3dc13970bb0b4562cf4f9b38f3edc46db.tar.xz gsoc2013-evolution-9b60cad3dc13970bb0b4562cf4f9b38f3edc46db.tar.zst gsoc2013-evolution-9b60cad3dc13970bb0b4562cf4f9b38f3edc46db.zip |
Read the characters as utf8, rather than as 8 bit bytes. Remove the
2003-01-13 Not Zed <NotZed@Ximian.com>
* camel-mime-filter-tohtml.c (writeln): Read the characters as
utf8, rather than as 8 bit bytes. Remove the PRESERVE_8BIT as it
has no meaning. Also change the default logic slightly so that 8
bit or greater characters are properly converted to entities.
* camel-utf8.c (camel_utf8_getc_limit): new function, gets a utf8
char, bounded by an end pointer.
svn path=/trunk/; revision=19421
Diffstat (limited to 'camel/camel-mime-filter-tohtml.c')
-rw-r--r-- | camel/camel-mime-filter-tohtml.c | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/camel/camel-mime-filter-tohtml.c b/camel/camel-mime-filter-tohtml.c index 4f9d972625..370d9c6c4e 100644 --- a/camel/camel-mime-filter-tohtml.c +++ b/camel/camel-mime-filter-tohtml.c @@ -28,6 +28,7 @@ #include <stdio.h> #include <string.h> +#include "camel-utf8.h" #include "camel-url-scanner.h" #include "camel-mime-filter-tohtml.h" @@ -147,14 +148,18 @@ static char * writeln (CamelMimeFilter *filter, const char *in, const char *inend, char *outptr, char **outend) { CamelMimeFilterToHTML *html = (CamelMimeFilterToHTML *) filter; - register const char *inptr = in; - + const char *inptr = in; + while (inptr < inend) { - unsigned char u; - - outptr = check_size (filter, outptr, outend, 9); - - switch ((u = (unsigned char) *inptr++)) { + guint32 u; + + outptr = check_size (filter, outptr, outend, 16); + + u = camel_utf8_getc_limit(&inptr, inend); + switch (u) { + case 0xffff: + g_warning("Truncated utf8 buffer"); + return outptr; case '<': outptr = g_stpcpy (outptr, "<"); html->column++; @@ -182,22 +187,21 @@ writeln (CamelMimeFilter *filter, const char *in, const char *inend, char *outpt } /* otherwise, FALL THROUGH */ case ' ': - if (html->flags & CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES) { - if (inptr == (in + 1) || *inptr == ' ' || *inptr == '\t') { - outptr = g_stpcpy (outptr, " "); - html->column++; - break; - } + if (html->flags & CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES + && ((inptr == (in + 1) || *inptr == ' ' || *inptr == '\t'))) { + outptr = g_stpcpy (outptr, " "); + html->column++; + break; } /* otherwise, FALL THROUGH */ default: - if (!(u >= 0x20 && u < 0x80) && !(html->flags & CAMEL_MIME_FILTER_TOHTML_PRESERVE_8BIT)) { + if (u >= 20 && u <0x80) + *outptr++ = u; + else { if (html->flags & CAMEL_MIME_FILTER_TOHTML_ESCAPE_8BIT) *outptr++ = '?'; else - outptr += g_snprintf (outptr, 9, "&#%d;", (int) u); - } else { - *outptr++ = (char) u; + outptr += sprintf(outptr, "&#%u;", u); } html->column++; break; |