changeset 34:f78ffe7ce43d

[/trunk] Changeset 50 by mikael * Fix a bug in the UTF-8 encoder.
author mikael
date Mon, 04 Apr 2005 18:00:51 +0000
parents bb9172f2cbf1
children a8ceaa3005fd
files mcabber/src/utf8.c
diffstat 1 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/utf8.c	Mon Apr 04 12:12:42 2005 +0000
+++ b/mcabber/src/utf8.c	Mon Apr 04 18:00:51 2005 +0000
@@ -41,17 +41,20 @@
 char *utf8_encode(const char *src)
 {
   char *ret = calloc(1, (strlen(src) * 2) + 1);
-  char *aux = ret;
+  unsigned char *aux = ret;
 
   while (*src) {
     unsigned char ch = *src++;
-    if (ch < 0x80) {
-      *aux = ch;
-    } else {			/* if (ch < 0x800) { */
-      *aux++ = 0xc0 | (ch >> 6 & 0x1f);
-      *aux = 0xc0 | (0x80 | (ch & 0x3f));
+    if (ch < 0x80U) {
+      *aux++ = ch;
+    } else if (ch < 0x800U) {			/* if (ch < 0x800) { */
+      *aux++ = 0xc0 | (ch >> 6);
+      *aux++ = 0x80 | (ch & 0x3f);
+    } else {
+      *aux++ = 0xe0 | (ch >> 12);
+      *aux++ = 0x80 | ((ch >> 6) & 0x3f);
+      *aux++ = 0x80 | (ch & 0x3f);
     }
-    aux++;
   }
 
   return ret;