Mercurial > pidgin
changeset 4855:e4bfaba117e4
[gaim-migrate @ 5182]
the real solution is to count string length better ;-)
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sat, 22 Mar 2003 16:43:41 +0000 |
parents | 3755ec4e3951 |
children | ac9ed6c5594f |
files | src/buddy.c |
diffstat | 1 files changed, 19 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/buddy.c Sat Mar 22 16:15:16 2003 +0000 +++ b/src/buddy.c Sat Mar 22 16:43:41 2003 +0000 @@ -894,37 +894,29 @@ } if(tmp) { - char *temp; - + char buf[32]; + char *c = tmp; + int length = 0, vis=0; + gboolean inside = FALSE; g_strdelimit(tmp, "\n", ' '); - if(strlen(tmp) > 20) { - char *c1, *c2; - - statustext = g_strdup_printf("%.20s... ", tmp); - - if ((c1 = strrchr(statustext, '&')) != NULL) { - if ((c2 = strrchr(statustext, ';')) == NULL || - c2 < c1) { - - char *new_statustext; - - /* We must escape this broken entity. */ - new_statustext = g_new0(char, strlen(statustext) + 5); + while(*c && vis < 20) { + if(*c == '&') + inside = TRUE; + if(!inside) + vis++; + if(*c == ';') + inside = FALSE; + length++; + c++; /* this is fun */ + } - strncpy(new_statustext, statustext, c1 - statustext); - sprintf(new_statustext + (c1 - statustext), - "&%s", c1 + 1); - - g_free(statustext); + if(vis == 20) + g_snprintf(buf, sizeof(buf), "%%.%ds...", length); + else + g_snprintf(buf, sizeof(buf), "%%s "); - statustext = new_statustext; - } - } - - } - else - statustext = g_strdup_printf("%s ", tmp); + statustext = g_strdup_printf(buf, tmp); g_free(tmp); }