Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/compl.c @ 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 | 9a68fe4515dc |
children | 366ef500c522 |
comparison
equal
deleted
inserted
replaced
1239:eb9fc5d6d085 | 1240:a54645448e00 |
---|---|
30 */ | 30 */ |
31 | 31 |
32 #include <string.h> | 32 #include <string.h> |
33 | 33 |
34 #include "compl.h" | 34 #include "compl.h" |
35 #include "utf8.h" | |
35 #include "roster.h" | 36 #include "roster.h" |
36 #include "events.h" | 37 #include "events.h" |
37 | 38 |
38 // Completion structure | 39 // Completion structure |
39 typedef struct { | 40 typedef struct { |
119 c->len_compl = 0; | 120 c->len_compl = 0; |
120 return NULL; | 121 return NULL; |
121 } | 122 } |
122 r = (char*)c->next->data; | 123 r = (char*)c->next->data; |
123 c->next = g_slist_next(c->next); | 124 c->next = g_slist_next(c->next); |
124 c->len_compl = strlen(r); | 125 if (!utf8_mode) { |
126 c->len_compl = strlen(r); | |
127 } else { | |
128 char *wc; | |
129 c->len_compl = 0; | |
130 for (wc = r; *wc; wc = next_char(wc)) | |
131 c->len_compl += get_char_width(wc); | |
132 } | |
125 return r; | 133 return r; |
126 } | 134 } |
127 | 135 |
128 | 136 |
129 /* Categories functions */ | 137 /* Categories functions */ |
150 // If word is not space-terminated, we add one trailing space | 158 // If word is not space-terminated, we add one trailing space |
151 for (nword = (char*)word; *nword; nword++) | 159 for (nword = (char*)word; *nword; nword++) |
152 ; | 160 ; |
153 if (nword > word) nword--; | 161 if (nword > word) nword--; |
154 if (*nword != ' ') { // Add a space | 162 if (*nword != ' ') { // Add a space |
155 nword = g_new(char, strlen(word)+2); | 163 nword = g_strdup_printf("%s ", word); |
156 strcpy(nword, word); | |
157 strcat(nword, " "); | |
158 } else { // word is fine | 164 } else { // word is fine |
159 nword = g_strdup(word); | 165 nword = g_strdup(word); |
160 } | 166 } |
161 | 167 |
162 // TODO Check word does not already exist | 168 // TODO Check word does not already exist |
182 // If word is not space-terminated, we add one trailing space | 188 // If word is not space-terminated, we add one trailing space |
183 for (nword = (char*)word; *nword; nword++) | 189 for (nword = (char*)word; *nword; nword++) |
184 ; | 190 ; |
185 if (nword > word) nword--; | 191 if (nword > word) nword--; |
186 if (*nword != ' ') { // Add a space | 192 if (*nword != ' ') { // Add a space |
187 nword = g_new(char, strlen(word)+2); | 193 nword = g_strdup_printf("%s ", word); |
188 strcpy(nword, word); | |
189 strcat(nword, " "); | |
190 } else { // word is fine | 194 } else { // word is fine |
191 nword = g_strdup(word); | 195 nword = g_strdup(word); |
192 } | 196 } |
193 | 197 |
194 sl_elt = cat->words; | 198 sl_elt = cat->words; |