summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/utf8.c16
-rw-r--r--src/common/utf8.h1
-rw-r--r--src/common/util.c17
3 files changed, 32 insertions, 2 deletions
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,