aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-01-27 06:54:00 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-01-27 06:54:00 +0000
commit7027c02cc3bdc7a946e5f6fed57d90a578d77d1a (patch)
tree9d25c7975035aed5ca7b679b53d5d9ae5ef13c1a
parent245dee73072f1859f887fb0b01792a2688574d53 (diff)
prevent character corruption on UTF-8 to ISO-2022-JP conversion.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@46 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog5
-rw-r--r--ChangeLog.ja5
-rw-r--r--src/codeconv.c104
3 files changed, 85 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index f7a3e275..68b2485c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-01-27
+
+ * src/codeconv.c: conv_utf8toeuc(), conv_utf8tojis(): added to
+ prevent character corruption on conversion.
+
2005-01-26
* src/stock_pixmap.[ch]
diff --git a/ChangeLog.ja b/ChangeLog.ja
index 54221b62..9bbe9e58 100644
--- a/ChangeLog.ja
+++ b/ChangeLog.ja
@@ -1,3 +1,8 @@
+2005-01-27
+
+ * src/codeconv.c: conv_utf8toeuc(), conv_utf8tojis(): 変換時の
+ 文字化けを防ぐために追加。
+
2005-01-26
* src/stock_pixmap.[ch]
diff --git a/src/codeconv.c b/src/codeconv.c
index 2ce49b2d..47404702 100644
--- a/src/codeconv.c
+++ b/src/codeconv.c
@@ -113,6 +113,9 @@ static void conv_sjistoutf8(gchar *outbuf, gint outlen, const gchar *inbuf);
static void conv_euctoutf8(gchar *outbuf, gint outlen, const gchar *inbuf);
static void conv_anytoutf8(gchar *outbuf, gint outlen, const gchar *inbuf);
+static void conv_utf8toeuc(gchar *outbuf, gint outlen, const gchar *inbuf);
+static void conv_utf8tojis(gchar *outbuf, gint outlen, const gchar *inbuf);
+
static void conv_unreadable_eucjp(gchar *str);
static void conv_unreadable_8bit(gchar *str);
static void conv_unreadable_latin(gchar *str);
@@ -396,39 +399,12 @@ static void conv_sjistoeuc(gchar *outbuf, gint outlen, const gchar *inbuf)
static void conv_jistoutf8(gchar *outbuf, gint outlen, const gchar *inbuf)
{
- static iconv_t cd = (iconv_t)-1;
- static gboolean iconv_ok = TRUE;
- gchar *tmpstr;
gchar *eucstr;
Xalloca(eucstr, outlen, return);
conv_jistoeuc(eucstr, outlen, inbuf);
-
- if (cd == (iconv_t)-1) {
- if (!iconv_ok) {
- strncpy2(outbuf, inbuf, outlen);
- return;
- }
- cd = iconv_open(CS_UTF_8, CS_EUC_JP_MS);
- if (cd == (iconv_t)-1) {
- cd = iconv_open(CS_UTF_8, CS_EUC_JP);
- if (cd == (iconv_t)-1) {
- g_warning("conv_jistoutf8(): %s\n",
- g_strerror(errno));
- iconv_ok = FALSE;
- strncpy2(outbuf, inbuf, outlen);
- return;
- }
- }
- }
-
- tmpstr = conv_iconv_strdup_with_cd(eucstr, cd);
- if (tmpstr) {
- strncpy2(outbuf, tmpstr, outlen);
- g_free(tmpstr);
- } else
- strncpy2(outbuf, inbuf, outlen);
+ conv_euctoutf8(outbuf, outlen, eucstr);
}
static void conv_sjistoutf8(gchar *outbuf, gint outlen, const gchar *inbuf)
@@ -445,9 +421,29 @@ static void conv_sjistoutf8(gchar *outbuf, gint outlen, const gchar *inbuf)
static void conv_euctoutf8(gchar *outbuf, gint outlen, const gchar *inbuf)
{
+ static iconv_t cd = (iconv_t)-1;
+ static gboolean iconv_ok = TRUE;
gchar *tmpstr;
- tmpstr = conv_iconv_strdup(inbuf, CS_EUC_JP, CS_UTF_8);
+ if (cd == (iconv_t)-1) {
+ if (!iconv_ok) {
+ strncpy2(outbuf, inbuf, outlen);
+ return;
+ }
+ cd = iconv_open(CS_UTF_8, CS_EUC_JP_MS);
+ if (cd == (iconv_t)-1) {
+ cd = iconv_open(CS_UTF_8, CS_EUC_JP);
+ if (cd == (iconv_t)-1) {
+ g_warning("conv_euctoutf8(): %s\n",
+ g_strerror(errno));
+ iconv_ok = FALSE;
+ strncpy2(outbuf, inbuf, outlen);
+ return;
+ }
+ }
+ }
+
+ tmpstr = conv_iconv_strdup_with_cd(inbuf, cd);
if (tmpstr) {
strncpy2(outbuf, tmpstr, outlen);
g_free(tmpstr);
@@ -473,6 +469,48 @@ static void conv_anytoutf8(gchar *outbuf, gint outlen, const gchar *inbuf)
}
}
+static void conv_utf8toeuc(gchar *outbuf, gint outlen, const gchar *inbuf)
+{
+ static iconv_t cd = (iconv_t)-1;
+ static gboolean iconv_ok = TRUE;
+ gchar *tmpstr;
+
+ if (cd == (iconv_t)-1) {
+ if (!iconv_ok) {
+ strncpy2(outbuf, inbuf, outlen);
+ return;
+ }
+ cd = iconv_open(CS_EUC_JP_MS, CS_UTF_8);
+ if (cd == (iconv_t)-1) {
+ cd = iconv_open(CS_EUC_JP, CS_UTF_8);
+ if (cd == (iconv_t)-1) {
+ g_warning("conv_utf8toeuc(): %s\n",
+ g_strerror(errno));
+ iconv_ok = FALSE;
+ strncpy2(outbuf, inbuf, outlen);
+ return;
+ }
+ }
+ }
+
+ tmpstr = conv_iconv_strdup_with_cd(inbuf, cd);
+ if (tmpstr) {
+ strncpy2(outbuf, tmpstr, outlen);
+ g_free(tmpstr);
+ } else
+ strncpy2(outbuf, inbuf, outlen);
+}
+
+static void conv_utf8tojis(gchar *outbuf, gint outlen, const gchar *inbuf)
+{
+ gchar *eucstr;
+
+ Xalloca(eucstr, outlen, return);
+
+ conv_utf8toeuc(eucstr, outlen, inbuf);
+ conv_euctojis(outbuf, outlen, eucstr);
+}
+
static gchar valid_eucjp_tbl[][96] = {
/* 0xa2a0 - 0xa2ff */
{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
@@ -910,6 +948,14 @@ CodeConvFunc conv_get_code_conv_func(const gchar *src_charset_str,
else if (dest_charset == C_UTF_8)
code_conv = conv_euctoutf8;
break;
+ case C_UTF_8:
+ if (dest_charset == C_EUC_JP)
+ code_conv = conv_utf8toeuc;
+ else if (dest_charset == C_ISO_2022_JP ||
+ dest_charset == C_ISO_2022_JP_2 ||
+ dest_charset == C_ISO_2022_JP_3)
+ code_conv = conv_utf8tojis;
+ break;
default:
break;
}