comparison src/util.c @ 4793:677d3cb193a1

[gaim-migrate @ 5113] this removes all the remaining deprecated glib, gdk, gdk-pixbuf, and gtk function calls. Hopefully I didn't break anything. Most of this is due to the deprecation of g_strcasecmp and g_strncasecmp. Two functions I never thought would be deprecated, but apparently they're no good at comparing utf8 text. g_ascii_str{,n}casecmp is OK when you're sure that it's ASCII. Otherwise, we're supposed to use g_utf8_collate(), except that it is case sensitive. Since glib doesn't currently have a case-insensitive one, I wrote one. If you need to compare utf8 text, you can use gaim_utf8_strcasecmp(). I have to go do dishes now. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 16 Mar 2003 00:01:49 +0000
parents 912bacf989d7
children 0ed37c803503
comparison
equal deleted inserted replaced
4792:9212d1c5b7dc 4793:677d3cb193a1
147 147
148 strncpy(cpy, text, strlen(text)); 148 strncpy(cpy, text, strlen(text));
149 cpy[strlen(text)] = 0; 149 cpy[strlen(text)] = 0;
150 c = cpy; 150 c = cpy;
151 while (*c) { 151 while (*c) {
152 if (!g_strncasecmp(c, "<A", 2)) { 152 if (!g_ascii_strncasecmp(c, "<A", 2)) {
153 while (1) { 153 while (1) {
154 if (!g_strncasecmp(c, "/A>", 3)) { 154 if (!g_ascii_strncasecmp(c, "/A>", 3)) {
155 break; 155 break;
156 } 156 }
157 text[cnt++] = *c; 157 text[cnt++] = *c;
158 c++; 158 c++;
159 if (!(*c)) 159 if (!(*c))
160 break; 160 break;
161 } 161 }
162 } else if ((*c=='h') && (!g_strncasecmp(c, "http://", 7) || (!g_strncasecmp(c, "https://", 8)))) { 162 } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) || (!g_ascii_strncasecmp(c, "https://", 8)))) {
163 t = c; 163 t = c;
164 while (1) { 164 while (1) {
165 if (badchar(*t)) { 165 if (badchar(*t)) {
166 166
167 if (*(t) == ',' && (*(t + 1) != ' ')) { 167 if (*(t) == ',' && (*(t + 1) != ' ')) {
181 if (!t) 181 if (!t)
182 break; 182 break;
183 t++; 183 t++;
184 184
185 } 185 }
186 } else if (!g_strncasecmp(c, "www.", 4)) { 186 } else if (!g_ascii_strncasecmp(c, "www.", 4)) {
187 if (c[4] != '.') { 187 if (c[4] != '.') {
188 t = c; 188 t = c;
189 while (1) { 189 while (1) {
190 if (badchar(*t)) { 190 if (badchar(*t)) {
191 if (t - c == 4) { 191 if (t - c == 4) {
210 if (!t) 210 if (!t)
211 break; 211 break;
212 t++; 212 t++;
213 } 213 }
214 } 214 }
215 } else if (!g_strncasecmp(c, "ftp://", 6)) { 215 } else if (!g_ascii_strncasecmp(c, "ftp://", 6)) {
216 t = c; 216 t = c;
217 while (1) { 217 while (1) {
218 if (badchar(*t)) { 218 if (badchar(*t)) {
219 if (*(t - 1) == '.') 219 if (*(t - 1) == '.')
220 t--; 220 t--;
228 if (!t) 228 if (!t)
229 break; 229 break;
230 t++; 230 t++;
231 231
232 } 232 }
233 } else if (!g_strncasecmp(c, "ftp.", 4)) { 233 } else if (!g_ascii_strncasecmp(c, "ftp.", 4)) {
234 if (c[4] != '.') { 234 if (c[4] != '.') {
235 t = c; 235 t = c;
236 while (1) { 236 while (1) {
237 if (badchar(*t)) { 237 if (badchar(*t)) {
238 if (t - c == 4) { 238 if (t - c == 4) {
251 if (!t) 251 if (!t)
252 break; 252 break;
253 t++; 253 t++;
254 } 254 }
255 } 255 }
256 } else if (!g_strncasecmp(c, "mailto:", 7)) { 256 } else if (!g_ascii_strncasecmp(c, "mailto:", 7)) {
257 t = c; 257 t = c;
258 while (1) { 258 while (1) {
259 if (badchar(*t)) { 259 if (badchar(*t)) {
260 if (*(t - 1) == '.') 260 if (*(t - 1) == '.')
261 t--; 261 t--;
468 468
469 469
470 char *normalize(const char *s) 470 char *normalize(const char *s)
471 { 471 {
472 static char buf[BUF_LEN]; 472 static char buf[BUF_LEN];
473 char *tmp;
473 int i, j; 474 int i, j;
474 475
475 g_return_val_if_fail((s != NULL), NULL); 476 g_return_val_if_fail((s != NULL), NULL);
476 477
477 strncpy(buf, s, BUF_LEN); 478 strncpy(buf, s, BUF_LEN);
479 while (buf[j] == ' ') 480 while (buf[j] == ' ')
480 j++; 481 j++;
481 buf[i] = buf[j]; 482 buf[i] = buf[j];
482 } 483 }
483 buf[i] = '\0'; 484 buf[i] = '\0';
484 g_strdown(buf); 485
486 tmp = g_utf8_strdown(buf, -1);
487 g_snprintf(buf, sizeof(buf), tmp);
488 g_free(tmp);
485 489
486 return buf; 490 return buf;
487 } 491 }
488 492
489 char *date() 493 char *date()
978 982
979 if (gc == NULL) 983 if (gc == NULL)
980 return _("Not connected to AIM"); 984 return _("Not connected to AIM");
981 985
982 /* aim:goim?screenname=screenname&message=message */ 986 /* aim:goim?screenname=screenname&message=message */
983 if (!g_strncasecmp(uri, "aim:goim?", strlen("aim:goim?"))) { 987 if (!g_ascii_strncasecmp(uri, "aim:goim?", strlen("aim:goim?"))) {
984 char *who, *what; 988 char *who, *what;
985 struct gaim_conversation *c; 989 struct gaim_conversation *c;
986 uri = uri + strlen("aim:goim?"); 990 uri = uri + strlen("aim:goim?");
987 991
988 if (!(who = strstr(uri, "screenname="))) { 992 if (!(who = strstr(uri, "screenname="))) {
1000 1004
1001 what = strstr(uri, "message="); 1005 what = strstr(uri, "message=");
1002 if (what) { 1006 if (what) {
1003 what = what + strlen("message="); 1007 what = what + strlen("message=");
1004 str = g_string_new(NULL); 1008 str = g_string_new(NULL);
1005 while (*what && (*what != '&' || !g_strncasecmp(what, "&amp;", 5))) { 1009 while (*what && (*what != '&' || !g_ascii_strncasecmp(what, "&amp;", 5))) {
1006 g_string_append_c(str, *what == '+' ? ' ' : *what); 1010 g_string_append_c(str, *what == '+' ? ' ' : *what);
1007 what++; 1011 what++;
1008 } 1012 }
1009 what = g_strdup(str->str); 1013 what = g_strdup(str->str);
1010 g_string_free(str, TRUE); 1014 g_string_free(str, TRUE);
1017 struct gaim_gtk_conversation *gtkconv = GAIM_GTK_CONVERSATION(c); 1021 struct gaim_gtk_conversation *gtkconv = GAIM_GTK_CONVERSATION(c);
1018 1022
1019 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, what, -1); 1023 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, what, -1);
1020 g_free(what); 1024 g_free(what);
1021 } 1025 }
1022 } else if (!g_strncasecmp(uri, "aim:addbuddy?", strlen("aim:addbuddy?"))) { 1026 } else if (!g_ascii_strncasecmp(uri, "aim:addbuddy?", strlen("aim:addbuddy?"))) {
1023 char *who, *group; 1027 char *who, *group;
1024 uri = uri + strlen("aim:addbuddy?"); 1028 uri = uri + strlen("aim:addbuddy?");
1025 /* spaces are encoded as +'s */ 1029 /* spaces are encoded as +'s */
1026 1030
1027 if (!(who = strstr(uri, "screenname="))) { 1031 if (!(who = strstr(uri, "screenname="))) {
1038 1042
1039 group = strstr(uri, "group="); 1043 group = strstr(uri, "group=");
1040 if (group) { 1044 if (group) {
1041 group = group + strlen("group="); 1045 group = group + strlen("group=");
1042 str = g_string_new(NULL); 1046 str = g_string_new(NULL);
1043 while (*group && (*group != '&' || !g_strncasecmp(group, "&amp;", 5))) { 1047 while (*group && (*group != '&' || !g_ascii_strncasecmp(group, "&amp;", 5))) {
1044 g_string_append_c(str, *group == '+' ? ' ' : *group); 1048 g_string_append_c(str, *group == '+' ? ' ' : *group);
1045 group++; 1049 group++;
1046 } 1050 }
1047 group = g_strdup(str->str); 1051 group = g_strdup(str->str);
1048 g_string_free(str, TRUE); 1052 g_string_free(str, TRUE);
1050 debug_printf("who: %s\n", who); 1054 debug_printf("who: %s\n", who);
1051 show_add_buddy(gc, who, group, NULL); 1055 show_add_buddy(gc, who, group, NULL);
1052 g_free(who); 1056 g_free(who);
1053 if (group) 1057 if (group)
1054 g_free(group); 1058 g_free(group);
1055 } else if (!g_strncasecmp(uri, "aim:gochat?", strlen("aim:gochat?"))) { 1059 } else if (!g_ascii_strncasecmp(uri, "aim:gochat?", strlen("aim:gochat?"))) {
1056 char *room; 1060 char *room;
1057 GList *chat=NULL; 1061 GList *chat=NULL;
1058 int exch = 5; 1062 int exch = 5;
1059 1063
1060 uri = uri + strlen("aim:gochat?"); 1064 uri = uri + strlen("aim:gochat?");
1242 /* Create our pixmap and pack it */ 1246 /* Create our pixmap and pack it */
1243 gtk_widget_realize(menu->parent); 1247 gtk_widget_realize(menu->parent);
1244 pm = gdk_pixmap_create_from_xpm_d(menu->parent->window, &mask, NULL, xpm); 1248 pm = gdk_pixmap_create_from_xpm_d(menu->parent->window, &mask, NULL, xpm);
1245 pixmap = gtk_image_new_from_pixmap(pm, mask); 1249 pixmap = gtk_image_new_from_pixmap(pm, mask);
1246 gtk_widget_show(pixmap); 1250 gtk_widget_show(pixmap);
1247 gdk_pixmap_unref(pm); 1251 g_object_unref(G_OBJECT(pm));
1248 gdk_bitmap_unref(mask); 1252 g_object_unref(G_OBJECT(mask));
1249 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, FALSE, 2); 1253 gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, FALSE, 2);
1250 1254
1251 /* Create our label and pack it */ 1255 /* Create our label and pack it */
1252 label = gtk_label_new(str); 1256 label = gtk_label_new(str);
1253 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2); 1257 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
1326 if (getsockname(fd, &addr, &namelen)) 1330 if (getsockname(fd, &addr, &namelen))
1327 return NULL; 1331 return NULL;
1328 1332
1329 return g_strdup(inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr)); 1333 return g_strdup(inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr));
1330 } 1334 }
1335
1336 gint gaim_utf8_strcasecmp(const gchar *a, const gchar *b) {
1337 gchar *a_norm = g_utf8_casefold(a, -1);
1338 gchar *b_norm = g_utf8_casefold(b, -1);
1339 gint ret = g_utf8_collate(a_norm, b_norm);
1340 g_free(a_norm);
1341 g_free(b_norm);
1342 return ret;
1343 }