comparison src/util.c @ 8341:fec4c1fb2ac8

[gaim-migrate @ 9065] Alright, I had to lay down a little bit of smack. Here goes: -Work around the rate-limit problem caused by Gaim auto-requesting away messages too quickly. Basically there is now a 1.2sec gap between each request. The downside is that it takes a bit longer for Gaim to get everyone's away message initially. Adium shouldn't need to do anything to take advantage of this. Fire (they use libfaim, right?) will need to add a callback for AIM_CB_LOC_REQUESTINFOTIMEOUT. Just search oscar.c for gaim_reqinfo_timeout() and copy what that thing does. -Attempt to do a better job showing away messages in tooltips. Hopefully & and greater than and less than will show up correctly now. I don't think there should be any side effects, but if you mouse over someone and it crashes or you get a pango error let me know. -Remove/combine some silly functions in util.c that few things use. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 26 Feb 2004 08:29:32 +0000
parents da57fb60680a
children 33cc36f5a7a6
comparison
equal deleted inserted replaced
8340:ab6ffc260785 8341:fec4c1fb2ac8
1640 } 1640 }
1641 cpy[cnt] = '\0'; 1641 cpy[cnt] = '\0';
1642 return (cpy); 1642 return (cpy);
1643 } 1643 }
1644 1644
1645 /* 1645 gchar *
1646 * rcg10312000 This could be more robust, but it works for my current 1646 gaim_strdup_withhtml(const gchar *src)
1647 * goal: to remove those annoying <BR> tags. :) 1647 {
1648 * dtf12162000 made the loop more readable. i am a neat freak. ;) */ 1648 gulong destsize, i, j;
1649 void 1649 gchar *dest;
1650 gaim_strncpy_nohtml(char *dest, const char *src, size_t destsize)
1651 {
1652 char *ptr;
1653
1654 g_return_if_fail(dest != NULL);
1655 g_return_if_fail(src != NULL);
1656 g_return_if_fail(destsize > 0);
1657
1658 g_snprintf(dest, destsize, "%s", src);
1659
1660 while ((ptr = strstr(dest, "<BR>")) != NULL) {
1661 /* replace <BR> with a newline. */
1662 *ptr = '\n';
1663 memmove(ptr + 1, ptr + 4, strlen(ptr + 4) + 1);
1664 }
1665 }
1666
1667 void
1668 gaim_strncpy_withhtml(gchar *dest, const gchar *src, size_t destsize)
1669 {
1670 gchar *end;
1671
1672 g_return_if_fail(dest != NULL);
1673 g_return_if_fail(src != NULL);
1674 g_return_if_fail(destsize > 0);
1675
1676 end = dest + destsize;
1677
1678 while (dest < end) {
1679 if (*src == '\n' && dest < end - 5) {
1680 strcpy(dest, "<BR>");
1681 src++;
1682 dest += 4;
1683 } else if(*src == '\r') {
1684 src++;
1685 } else {
1686 *dest++ = *src;
1687 if (*src == '\0')
1688 return;
1689 else
1690 src++;
1691 }
1692 }
1693 }
1694
1695 /*
1696 * Like strncpy_withhtml (above), but malloc()'s the necessary space
1697 *
1698 * The caller is responsible for freeing the space pointed to by the
1699 * return value.
1700 */
1701 char *
1702 gaim_strdup_withhtml(const char *src)
1703 {
1704 char *sp, *dest;
1705 gulong destsize;
1706 1650
1707 g_return_val_if_fail(src != NULL, NULL); 1651 g_return_val_if_fail(src != NULL, NULL);
1708 1652
1709 /* 1653 /* New length is (length of src) + (number of \n's * 3) + 1 */
1710 * All we need do is multiply the number of newlines by 3 (the 1654 for (i = 0, j = 0; src[i] != '\0'; i++)
1711 * additional length of "<BR>" over "\n"), account for the 1655 if (src[i] == '\n')
1712 * terminator, malloc the space and call strncpy_withhtml. 1656 j++;
1713 */ 1657
1714 for(destsize = 0, sp = (gchar *)src; 1658 destsize = i + (j * 3) + 1;
1715 (sp = strchr(sp, '\n')) != NULL;
1716 ++sp, ++destsize)
1717 ;
1718
1719 destsize *= 3;
1720 destsize += strlen(src) + 1;
1721 dest = g_malloc(destsize); 1659 dest = g_malloc(destsize);
1722 gaim_strncpy_withhtml(dest, src, destsize); 1660
1661 /* Copy stuff, ignoring \r's, because they are dumb */
1662 for (i = 0, j = 0; src[i] != '\0'; i++) {
1663 if (src[i] == '\n') {
1664 strcpy(&dest[j], "<BR>");
1665 j += 4;
1666 } else if (src[i] != '\r')
1667 dest[j++] = src[i];
1668 }
1669
1670 dest[destsize-1] = '\0';
1723 1671
1724 return dest; 1672 return dest;
1725 } 1673 }
1726 1674
1727 gboolean 1675 gboolean
1797 1745
1798 strcpy(text, text2); 1746 strcpy(text, text2);
1799 g_free(text2); 1747 g_free(text2);
1800 } 1748 }
1801 1749
1802 char * 1750 gchar *
1803 gaim_strreplace(const char *string, const char *delimiter, 1751 gaim_strreplace(const char *string, const char *delimiter,
1804 const char *replacement) 1752 const char *replacement)
1805 { 1753 {
1806 gchar **split; 1754 gchar **split;
1807 gchar *ret; 1755 gchar *ret;
1811 g_return_val_if_fail(replacement != NULL, NULL); 1759 g_return_val_if_fail(replacement != NULL, NULL);
1812 1760
1813 split = g_strsplit(string, delimiter, 0); 1761 split = g_strsplit(string, delimiter, 0);
1814 ret = g_strjoinv(replacement, split); 1762 ret = g_strjoinv(replacement, split);
1815 g_strfreev(split); 1763 g_strfreev(split);
1764
1765 return ret;
1766 }
1767
1768 gchar *
1769 gaim_strcasereplace(const char *string, const char *delimiter,
1770 const char *replacement)
1771 {
1772 gchar *ret;
1773 int length_del, length_rep, i, j;
1774
1775 g_return_val_if_fail(string != NULL, NULL);
1776 g_return_val_if_fail(delimiter != NULL, NULL);
1777 g_return_val_if_fail(replacement != NULL, NULL);
1778
1779 length_del = strlen(delimiter);
1780 length_rep = strlen(replacement);
1781
1782 /* Count how many times the delimiter appears */
1783 i = 0; /* position in the source string */
1784 j = 0; /* number of occurences of "delimiter" */
1785 while (string[i] != '\0') {
1786 if (!strncasecmp(&string[i], delimiter, length_del)) {
1787 i += length_del;
1788 j += length_rep;
1789 } else {
1790 i++;
1791 j++;
1792 }
1793 }
1794
1795 ret = g_malloc(j+1);
1796
1797 i = 0; /* position in the source string */
1798 j = 0; /* position in the destination string */
1799 while (string[i] != '\0') {
1800 if (!strncasecmp(&string[i], delimiter, length_del)) {
1801 strncpy(&ret[j], replacement, length_rep);
1802 i += length_del;
1803 j += length_rep;
1804 } else {
1805 ret[j] = string[i];
1806 i++;
1807 j++;
1808 }
1809 }
1810
1811 ret[j] = '\0';
1816 1812
1817 return ret; 1813 return ret;
1818 } 1814 }
1819 1815
1820 const char * 1816 const char *