# HG changeset patch # User Mark Doliner # Date 1130732826 0 # Node ID 52f27ffe68a551992fc3f44b66ba89cb0b46f08c # Parent 51832ad72a6b02ea6157230bca35382706e1079b [gaim-migrate @ 14211] sf patch #1339035, from Sadrul Habib Chowdhury "Remove the \n in Yahoo! status messages when showing them in the buddy list inline." Also some changes from me. I changed gaim_str_strip_cr(char *text) to gaim_str_strip_char(char *text, char thechar). I don't know why, really, but it seems like it could be more useful this way. Eh committer: Tailor Script diff -r 51832ad72a6b -r 52f27ffe68a5 plugins/perl/common/Util.xs --- a/plugins/perl/common/Util.xs Mon Oct 31 03:55:56 2005 +0000 +++ b/plugins/perl/common/Util.xs Mon Oct 31 04:27:06 2005 +0000 @@ -169,8 +169,9 @@ size_t size void -gaim_str_strip_cr(str) +gaim_str_strip_char(str, thechar) char *str + char thechar gchar * gaim_str_sub_away_formatters(str, name) diff -r 51832ad72a6b -r 52f27ffe68a5 src/account.c --- a/src/account.c Mon Oct 31 03:55:56 2005 +0000 +++ b/src/account.c Mon Oct 31 04:27:06 2005 +0000 @@ -338,7 +338,7 @@ if ((tmp = gaim_account_get_user_info(account)) != NULL) { - /* TODO: Do we need to call gaim_str_strip_cr(tmp) here? */ + /* TODO: Do we need to call gaim_str_strip_char(tmp, '\r') here? */ child = xmlnode_new_child(node, "userinfo"); xmlnode_insert_data(child, tmp, -1); } diff -r 51832ad72a6b -r 52f27ffe68a5 src/gtkblist.c --- a/src/gtkblist.c Mon Oct 31 03:55:56 2005 +0000 +++ b/src/gtkblist.c Mon Oct 31 04:27:06 2005 +0000 @@ -2844,7 +2844,7 @@ int length = 0, vis=0; gboolean inside = FALSE; g_strdelimit(tmp, "\n", ' '); - gaim_str_strip_cr(tmp); + gaim_str_strip_char(tmp, '\r'); while(*c && vis < 20) { if(*c == '&') @@ -3368,7 +3368,7 @@ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Tools/Mute Sounds"))), gaim_prefs_get_bool("/gaim/gtk/sound/mute")); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtk_item_factory_get_item (gtkblist->ift, N_("/Buddies/Show Buddy Details"))), - gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")); + gaim_prefs_get_bool("/gaim/gtk/blist/show_buddy_icons")); if(!strcmp(gaim_prefs_get_string("/gaim/gtk/sound/method"), "none")) gtk_widget_set_sensitive(gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Mute Sounds")), FALSE); diff -r 51832ad72a6b -r 52f27ffe68a5 src/gtkimhtml.c --- a/src/gtkimhtml.c Mon Oct 31 03:55:56 2005 +0000 +++ b/src/gtkimhtml.c Mon Oct 31 04:27:06 2005 +0000 @@ -1640,7 +1640,7 @@ switch (info) { case GTK_IMHTML_DRAG_URL: /* TODO: Is it really ok to change sd->data...? */ - gaim_str_strip_cr((char *)sd->data); + gaim_str_strip_char((char *)sd->data, '\r'); links = g_strsplit((char *)sd->data, "\n", 0); while((link = links[i]) != NULL){ diff -r 51832ad72a6b -r 52f27ffe68a5 src/log.c --- a/src/log.c Mon Oct 31 03:55:56 2005 +0000 +++ b/src/log.c Mon Oct 31 04:27:06 2005 +0000 @@ -123,7 +123,7 @@ g_return_val_if_fail(log && log->logger, NULL); if (log->logger->read) { char *ret = (log->logger->read)(log, flags ? flags : &mflags); - gaim_str_strip_cr(ret); + gaim_str_strip_char(ret, '\r'); return ret; } return (_("The logger has no read function")); diff -r 51832ad72a6b -r 52f27ffe68a5 src/protocols/gg/gg.c --- a/src/protocols/gg/gg.c Mon Oct 31 03:55:56 2005 +0000 +++ b/src/protocols/gg/gg.c Mon Oct 31 04:27:06 2005 +0000 @@ -762,7 +762,7 @@ msg = charset_convert((const char *)ev->event.msg.message, "CP1250", "UTF-8"); - gaim_str_strip_cr(msg); + gaim_str_strip_char(msg, '\r'); tmp = g_markup_escape_text(msg, -1); gaim_debug_info("gg", "msg form (%s): %s (class = %d; rcpt_count = %d)\n", diff -r 51832ad72a6b -r 52f27ffe68a5 src/protocols/msn/msn.c --- a/src/protocols/msn/msn.c Mon Oct 31 03:55:56 2005 +0000 +++ b/src/protocols/msn/msn.c Mon Oct 31 04:27:06 2005 +0000 @@ -1513,7 +1513,7 @@ } /* Nuke the nasty \r's that just get in the way */ - gaim_str_strip_cr(url_buffer); + gaim_str_strip_char(url_buffer, '\r'); /* MSN always puts in ' for apostrophes...replace them */ while ((p = strstr(url_buffer, "'")) != NULL) diff -r 51832ad72a6b -r 52f27ffe68a5 src/protocols/oscar/oscar.c --- a/src/protocols/oscar/oscar.c Mon Oct 31 03:55:56 2005 +0000 +++ b/src/protocols/oscar/oscar.c Mon Oct 31 04:27:06 2005 +0000 @@ -4524,7 +4524,7 @@ for (numtoks=0; msg1[numtoks]; numtoks++); msg2 = (gchar **)g_malloc((numtoks+1)*sizeof(gchar *)); for (i=0; msg1[i]; i++) { - gaim_str_strip_cr(msg1[i]); + gaim_str_strip_char(msg1[i], '\r'); msg2[i] = gaim_plugin_oscar_decode_im_part(account, "1", AIM_CHARSET_ASCII, 0x0000, msg1[i], strlen(msg1[i])); } msg2[i] = NULL; @@ -5089,7 +5089,7 @@ tmp = gaim_str_sub_away_formatters(str->str, gaim_account_get_username(account)); g_string_free(str, TRUE); - gaim_str_strip_cr(tmp); + gaim_str_strip_char(tmp, '\r'); gaim_notify_userinfo(gc, userinfo->sn, tmp, NULL, NULL); g_free(tmp); diff -r 51832ad72a6b -r 52f27ffe68a5 src/protocols/yahoo/yahoo.c --- a/src/protocols/yahoo/yahoo.c Mon Oct 31 03:55:56 2005 +0000 +++ b/src/protocols/yahoo/yahoo.c Mon Oct 31 04:27:06 2005 +0000 @@ -744,7 +744,7 @@ } m = yahoo_string_decode(gc, im->msg, im->utf8); - gaim_str_strip_cr(m); + gaim_str_strip_char(m, '\r'); if (!strcmp(m, "")) { GaimConversation *c = gaim_conversation_new(GAIM_CONV_TYPE_IM, @@ -2717,6 +2717,7 @@ { YahooFriend *f = NULL; const char *msg; + char *msg2; f = yahoo_friend_find(b->account->gc, b->name); if (!f) @@ -2732,7 +2733,9 @@ case YAHOO_STATUS_CUSTOM: if (!(msg = yahoo_friend_get_status_message(f))) return NULL; - return g_markup_escape_text(msg, strlen(msg)); + msg2 = g_markup_escape_text(msg, strlen(msg)); + gaim_util_chrreplace(msg2, '\n', ' '); + return msg2; default: return g_strdup(yahoo_get_status_string(f->status)); diff -r 51832ad72a6b -r 52f27ffe68a5 src/protocols/yahoo/yahoo_profile.c --- a/src/protocols/yahoo/yahoo_profile.c Mon Oct 31 03:55:56 2005 +0000 +++ b/src/protocols/yahoo/yahoo_profile.c Mon Oct 31 04:27:06 2005 +0000 @@ -861,7 +861,7 @@ #endif /* nuke the nasty \r's */ - gaim_str_strip_cr(url_buffer); + gaim_str_strip_char(url_buffer, '\r'); #if PHOTO_SUPPORT /* Marshall the existing state */ diff -r 51832ad72a6b -r 52f27ffe68a5 src/util.c --- a/src/util.c Mon Oct 31 03:55:56 2005 +0000 +++ b/src/util.c Mon Oct 31 04:27:06 2005 +0000 @@ -2465,19 +2465,35 @@ } void -gaim_str_strip_cr(char *text) +gaim_str_strip_char(char *text, char thechar) { int i, j; g_return_if_fail(text != NULL); for (i = 0, j = 0; text[i]; i++) - if (text[i] != '\r') + if (text[i] != thechar) text[j++] = text[i]; text[j++] = '\0'; } +void +gaim_util_chrreplace(char *string, char delimiter, + char replacement) +{ + int i = 0; + + g_return_if_fail(string != NULL); + + while (string[i] != '\0') + { + if (string[i] == delimiter) + string[i] = replacement; + i++; + } +} + gchar * gaim_strreplace(const char *string, const char *delimiter, const char *replacement) diff -r 51832ad72a6b -r 52f27ffe68a5 src/util.h --- a/src/util.h Mon Oct 31 03:55:56 2005 +0000 +++ b/src/util.h Mon Oct 31 04:27:06 2005 +0000 @@ -574,11 +574,30 @@ char *gaim_str_add_cr(const char *str); /** - * Strips all carriage returns from a string. + * Strips all instances of the given character from the + * given string. The string is modified in place. This + * is useful for stripping new line characters, for example. + * + * Example usage: + * gaim_str_strip_char(my_dumb_string, '\n'); * - * @param str The string to strip carriage returns from. + * @param str The string to strip characters from. + * @param thechar The character to strip from the given string. */ -void gaim_str_strip_cr(char *str); +void gaim_str_strip_char(char *str, char thechar); + +/** + * Given a string, this replaces all instances of one character + * with another. This happens inline (the original string IS + * modified). + * + * @param string The string from which to replace stuff. + * @param delimiter The character you want replaced. + * @param replacement The character you want inserted in place + * of the delimiting character. + */ +void gaim_util_chrreplace(char *string, char delimiter, + char replacement); /** * Given a string, this replaces one substring with another