diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/common/utf8.c | 16 | ||||
-rw-r--r-- | src/common/utf8.h | 1 | ||||
-rw-r--r-- | src/common/util.c | 17 | ||||
-rw-r--r-- | weechat/ChangeLog | 3 | ||||
-rw-r--r-- | weechat/src/common/utf8.c | 16 | ||||
-rw-r--r-- | weechat/src/common/utf8.h | 1 | ||||
-rw-r--r-- | weechat/src/common/util.c | 17 |
8 files changed, 68 insertions, 6 deletions
@@ -1,10 +1,11 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2007-04-25 +ChangeLog - 2007-05-02 Version 0.2.5 (under dev!): + * fixed bug with iso2022jp locale (bug #18719) * fixed string format bug when displaying string thru plugin script API * added /reconnect command (task #5448) * added "-all" option for /connect and /disconnect commands (task #6232) diff --git a/src/common/utf8.c b/src/common/utf8.c index 89744d6bd..33d96ec17 100644 --- a/src/common/utf8.c +++ b/src/common/utf8.c @@ -56,6 +56,22 @@ utf8_init () } /* + * utf8_has_8bits: return 1 if string has 8-bits chars, 0 if only 7-bits chars + */ + +int +utf8_has_8bits (char *string) +{ + while (string && string[0]) + { + if (string[0] & 0x80) + return 1; + string++; + } + return 0; +} + +/* * utf8_is_valid: return 1 if UTF-8 string is valid, 0 otherwise * if error is not NULL, it's set with first non valid UTF-8 * char in string, if any diff --git a/src/common/utf8.h b/src/common/utf8.h index 990b86fc1..861efe59b 100644 --- a/src/common/utf8.h +++ b/src/common/utf8.h @@ -24,6 +24,7 @@ extern int local_utf8; extern void utf8_init (); +extern int utf8_has_8bits (char *); extern int utf8_is_valid (char *, char **); extern void utf8_normalize (char *, char); extern char *utf8_prev_char (char *, char *); diff --git a/src/common/util.c b/src/common/util.c index badc22b61..b7c6907da 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -201,6 +201,7 @@ weechat_iconv (int from_utf8, char *from_code, char *to_code, char *string) #ifdef HAVE_ICONV iconv_t cd; char *inbuf, *ptr_inbuf, *ptr_outbuf, *next_char; + char *ptr_inbuf_shift; int done; size_t err, inbytesleft, outbytesleft; @@ -218,6 +219,7 @@ weechat_iconv (int from_utf8, char *from_code, char *to_code, char *string) outbytesleft = inbytesleft * 4; outbuf = (char *) malloc (outbytesleft + 2); ptr_outbuf = outbuf; + ptr_inbuf_shift = NULL; done = 0; while (!done) { @@ -260,8 +262,19 @@ weechat_iconv (int from_utf8, char *from_code, char *to_code, char *string) } } else - done = 1; + { + if (!ptr_inbuf_shift) + { + ptr_inbuf_shift = ptr_inbuf; + ptr_inbuf = NULL; + inbytesleft = 0; + } + else + done = 1; + } } + if (ptr_inbuf_shift) + ptr_inbuf = ptr_inbuf_shift; ptr_outbuf[0] = '\0'; free (inbuf); iconv_close (cd); @@ -298,7 +311,7 @@ weechat_iconv_to_internal (char *charset, char *string) if (input) { - if (utf8_is_valid (input, NULL)) + if (utf8_has_8bits (input) && utf8_is_valid (input, NULL)) return input; output = weechat_iconv (0, diff --git a/weechat/ChangeLog b/weechat/ChangeLog index 6582d8075..9f36c5674 100644 --- a/weechat/ChangeLog +++ b/weechat/ChangeLog @@ -1,10 +1,11 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2007-04-25 +ChangeLog - 2007-05-02 Version 0.2.5 (under dev!): + * fixed bug with iso2022jp locale (bug #18719) * fixed string format bug when displaying string thru plugin script API * added /reconnect command (task #5448) * added "-all" option for /connect and /disconnect commands (task #6232) diff --git a/weechat/src/common/utf8.c b/weechat/src/common/utf8.c index 89744d6bd..33d96ec17 100644 --- a/weechat/src/common/utf8.c +++ b/weechat/src/common/utf8.c @@ -56,6 +56,22 @@ utf8_init () } /* + * utf8_has_8bits: return 1 if string has 8-bits chars, 0 if only 7-bits chars + */ + +int +utf8_has_8bits (char *string) +{ + while (string && string[0]) + { + if (string[0] & 0x80) + return 1; + string++; + } + return 0; +} + +/* * utf8_is_valid: return 1 if UTF-8 string is valid, 0 otherwise * if error is not NULL, it's set with first non valid UTF-8 * char in string, if any diff --git a/weechat/src/common/utf8.h b/weechat/src/common/utf8.h index 990b86fc1..861efe59b 100644 --- a/weechat/src/common/utf8.h +++ b/weechat/src/common/utf8.h @@ -24,6 +24,7 @@ extern int local_utf8; extern void utf8_init (); +extern int utf8_has_8bits (char *); extern int utf8_is_valid (char *, char **); extern void utf8_normalize (char *, char); extern char *utf8_prev_char (char *, char *); diff --git a/weechat/src/common/util.c b/weechat/src/common/util.c index badc22b61..b7c6907da 100644 --- a/weechat/src/common/util.c +++ b/weechat/src/common/util.c @@ -201,6 +201,7 @@ weechat_iconv (int from_utf8, char *from_code, char *to_code, char *string) #ifdef HAVE_ICONV iconv_t cd; char *inbuf, *ptr_inbuf, *ptr_outbuf, *next_char; + char *ptr_inbuf_shift; int done; size_t err, inbytesleft, outbytesleft; @@ -218,6 +219,7 @@ weechat_iconv (int from_utf8, char *from_code, char *to_code, char *string) outbytesleft = inbytesleft * 4; outbuf = (char *) malloc (outbytesleft + 2); ptr_outbuf = outbuf; + ptr_inbuf_shift = NULL; done = 0; while (!done) { @@ -260,8 +262,19 @@ weechat_iconv (int from_utf8, char *from_code, char *to_code, char *string) } } else - done = 1; + { + if (!ptr_inbuf_shift) + { + ptr_inbuf_shift = ptr_inbuf; + ptr_inbuf = NULL; + inbytesleft = 0; + } + else + done = 1; + } } + if (ptr_inbuf_shift) + ptr_inbuf = ptr_inbuf_shift; ptr_outbuf[0] = '\0'; free (inbuf); iconv_close (cd); @@ -298,7 +311,7 @@ weechat_iconv_to_internal (char *charset, char *string) if (input) { - if (utf8_is_valid (input, NULL)) + if (utf8_has_8bits (input) && utf8_is_valid (input, NULL)) return input; output = weechat_iconv (0, |