From 761f4d1834b3217b5f9926baf0b9824234b51ef9 Mon Sep 17 00:00:00 2001 From: hiro Date: Tue, 12 Sep 2006 06:19:36 +0000 Subject: made workaround for UTF-8 with BOM. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1150 ee746299-78ed-0310-b773-934348b2243d --- libsylph/codeconv.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'libsylph') diff --git a/libsylph/codeconv.c b/libsylph/codeconv.c index 981ca7f2..dc071dad 100644 --- a/libsylph/codeconv.c +++ b/libsylph/codeconv.c @@ -108,6 +108,10 @@ typedef enum #define isutf8_3_2(c) \ (((c) & 0xc0) == 0x80) +#define isutf8bom(s) \ + (((*(s)) & 0xff) == 0xef && ((*(s + 1)) & 0xff) == 0xbb && \ + ((*(s + 2)) & 0xff) == 0xbf) + #define K_IN() \ if (state != JIS_KANJI) { \ *out++ = ESC; \ @@ -831,6 +835,12 @@ static gchar *conv_anytoutf8(const gchar *inbuf, gint *error) return conv_sjistoutf8(inbuf, error); case C_EUC_JP: return conv_euctoutf8(inbuf, error); + case C_UTF_8: + if (error) + *error = 0; + if (isutf8bom(inbuf)) + inbuf += 3; + return g_strdup(inbuf); default: if (error) *error = 0; @@ -864,6 +874,8 @@ static gchar *conv_utf8tosjis(const gchar *inbuf, gint *error) } } + if (isutf8bom(inbuf)) + inbuf += 3; return conv_iconv_strdup_with_cd(inbuf, cd, error); } @@ -893,6 +905,8 @@ static gchar *conv_utf8toeuc(const gchar *inbuf, gint *error) } } + if (isutf8bom(inbuf)) + inbuf += 3; return conv_iconv_strdup_with_cd(inbuf, cd, error); } @@ -1217,6 +1231,8 @@ gchar *conv_utf8todisp(const gchar *inbuf, gint *error) if (g_utf8_validate(inbuf, -1, NULL) == TRUE) { if (error) *error = 0; + if (isutf8bom(inbuf)) + inbuf += 3; return g_strdup(inbuf); } else return conv_ustodisp(inbuf, error); -- cgit v1.2.3