changeset 1240:a54645448e00

Fix completion of strings with multibyte chars Also get rid of some strcpy() + strcat() sequences.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 16 Jun 2007 17:48:37 +0200
parents eb9fc5d6d085
children 3a4018f18bdf
files mcabber/src/compl.c
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/compl.c	Sat Jun 16 17:17:04 2007 +0200
+++ b/mcabber/src/compl.c	Sat Jun 16 17:48:37 2007 +0200
@@ -32,6 +32,7 @@
 #include <string.h>
 
 #include "compl.h"
+#include "utf8.h"
 #include "roster.h"
 #include "events.h"
 
@@ -121,7 +122,14 @@
   }
   r = (char*)c->next->data;
   c->next = g_slist_next(c->next);
-  c->len_compl = strlen(r);
+  if (!utf8_mode) {
+    c->len_compl = strlen(r);
+  } else {
+    char *wc;
+    c->len_compl = 0;
+    for (wc = r; *wc; wc = next_char(wc))
+      c->len_compl += get_char_width(wc);
+  }
   return r;
 }
 
@@ -152,9 +160,7 @@
     ;
   if (nword > word) nword--;
   if (*nword != ' ') {  // Add a space
-    nword = g_new(char, strlen(word)+2);
-    strcpy(nword, word);
-    strcat(nword, " ");
+    nword = g_strdup_printf("%s ", word);
   } else {              // word is fine
     nword = g_strdup(word);
   }
@@ -184,9 +190,7 @@
     ;
   if (nword > word) nword--;
   if (*nword != ' ') {  // Add a space
-    nword = g_new(char, strlen(word)+2);
-    strcpy(nword, word);
-    strcat(nword, " ");
+    nword = g_strdup_printf("%s ", word);
   } else {              // word is fine
     nword = g_strdup(word);
   }