# HG changeset patch # User Mikael Berthe # Date 1182008917 -7200 # Node ID a54645448e0031ec5eea6622f75c550477065cb3 # Parent eb9fc5d6d085bb9767ac7da397a807a449e666a6 Fix completion of strings with multibyte chars Also get rid of some strcpy() + strcat() sequences. diff -r eb9fc5d6d085 -r a54645448e00 mcabber/src/compl.c --- 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 #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); }