Mercurial > pidgin
comparison libpurple/util.c @ 18397:e122b631a657
Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
effort to make libpurple compile with Visual Studio. --rlaager
committer: Richard Laager <rlaager@wiktel.com>
author | Nick Hebner <hebnern@gmail.com> |
---|---|
date | Sun, 01 Jul 2007 01:25:02 +0000 |
parents | c5c265dff90c |
children | 274a08f56ea6 5c1ed6296b56 |
comparison
equal
deleted
inserted
replaced
18396:864c454a5e16 | 18397:e122b631a657 |
---|---|
1728 if (str2[i] == '<') | 1728 if (str2[i] == '<') |
1729 { | 1729 { |
1730 if (cdata_close_tag) | 1730 if (cdata_close_tag) |
1731 { | 1731 { |
1732 /* Note: Don't even assume any other tag is a tag in CDATA */ | 1732 /* Note: Don't even assume any other tag is a tag in CDATA */ |
1733 if (strncasecmp(str2 + i, cdata_close_tag, | 1733 if (g_ascii_strncasecmp(str2 + i, cdata_close_tag, |
1734 strlen(cdata_close_tag)) == 0) | 1734 strlen(cdata_close_tag)) == 0) |
1735 { | 1735 { |
1736 i += strlen(cdata_close_tag) - 1; | 1736 i += strlen(cdata_close_tag) - 1; |
1737 cdata_close_tag = NULL; | 1737 cdata_close_tag = NULL; |
1738 } | 1738 } |
1739 continue; | 1739 continue; |
1740 } | 1740 } |
1741 else if (strncasecmp(str2 + i, "<td", 3) == 0 && closing_td_p) | 1741 else if (g_ascii_strncasecmp(str2 + i, "<td", 3) == 0 && closing_td_p) |
1742 { | 1742 { |
1743 str2[j++] = '\t'; | 1743 str2[j++] = '\t'; |
1744 visible = TRUE; | 1744 visible = TRUE; |
1745 } | 1745 } |
1746 else if (strncasecmp(str2 + i, "</td>", 5) == 0) | 1746 else if (g_ascii_strncasecmp(str2 + i, "</td>", 5) == 0) |
1747 { | 1747 { |
1748 closing_td_p = TRUE; | 1748 closing_td_p = TRUE; |
1749 visible = FALSE; | 1749 visible = FALSE; |
1750 } | 1750 } |
1751 else | 1751 else |
1769 k++; | 1769 k++; |
1770 } | 1770 } |
1771 | 1771 |
1772 /* If we've got an <a> tag with an href, save the address | 1772 /* If we've got an <a> tag with an href, save the address |
1773 * to print later. */ | 1773 * to print later. */ |
1774 if (strncasecmp(str2 + i, "<a", 2) == 0 && | 1774 if (g_ascii_strncasecmp(str2 + i, "<a", 2) == 0 && |
1775 g_ascii_isspace(str2[i+2])) | 1775 g_ascii_isspace(str2[i+2])) |
1776 { | 1776 { |
1777 int st; /* start of href, inclusive [ */ | 1777 int st; /* start of href, inclusive [ */ |
1778 int end; /* end of href, exclusive ) */ | 1778 int end; /* end of href, exclusive ) */ |
1779 char delim = ' '; | 1779 char delim = ' '; |
1780 /* Find start of href */ | 1780 /* Find start of href */ |
1781 for (st = i + 3; st < k; st++) | 1781 for (st = i + 3; st < k; st++) |
1782 { | 1782 { |
1783 if (strncasecmp(str2+st, "href=", 5) == 0) | 1783 if (g_ascii_strncasecmp(str2+st, "href=", 5) == 0) |
1784 { | 1784 { |
1785 st += 5; | 1785 st += 5; |
1786 if (str2[st] == '"' || str2[st] == '\'') | 1786 if (str2[st] == '"' || str2[st] == '\'') |
1787 { | 1787 { |
1788 delim = str2[st]; | 1788 delim = str2[st]; |
1810 } | 1810 } |
1811 } | 1811 } |
1812 | 1812 |
1813 /* Replace </a> with an ascii representation of the | 1813 /* Replace </a> with an ascii representation of the |
1814 * address the link was pointing to. */ | 1814 * address the link was pointing to. */ |
1815 else if (href != NULL && strncasecmp(str2 + i, "</a>", 4) == 0) | 1815 else if (href != NULL && g_ascii_strncasecmp(str2 + i, "</a>", 4) == 0) |
1816 { | 1816 { |
1817 | 1817 |
1818 size_t hrlen = strlen(href); | 1818 size_t hrlen = strlen(href); |
1819 | 1819 |
1820 /* Only insert the href if it's different from the CDATA. */ | 1820 /* Only insert the href if it's different from the CDATA. */ |
1832 href = NULL; | 1832 href = NULL; |
1833 } | 1833 } |
1834 } | 1834 } |
1835 | 1835 |
1836 /* Check for tags which should be mapped to newline */ | 1836 /* Check for tags which should be mapped to newline */ |
1837 else if (strncasecmp(str2 + i, "<p>", 3) == 0 | 1837 else if (g_ascii_strncasecmp(str2 + i, "<p>", 3) == 0 |
1838 || strncasecmp(str2 + i, "<tr", 3) == 0 | 1838 || g_ascii_strncasecmp(str2 + i, "<tr", 3) == 0 |
1839 || strncasecmp(str2 + i, "<br", 3) == 0 | 1839 || g_ascii_strncasecmp(str2 + i, "<br", 3) == 0 |
1840 || strncasecmp(str2 + i, "<hr", 3) == 0 | 1840 || g_ascii_strncasecmp(str2 + i, "<hr", 3) == 0 |
1841 || strncasecmp(str2 + i, "<li", 3) == 0 | 1841 || g_ascii_strncasecmp(str2 + i, "<li", 3) == 0 |
1842 || strncasecmp(str2 + i, "<div", 4) == 0 | 1842 || g_ascii_strncasecmp(str2 + i, "<div", 4) == 0 |
1843 || strncasecmp(str2 + i, "</table>", 8) == 0) | 1843 || g_ascii_strncasecmp(str2 + i, "</table>", 8) == 0) |
1844 { | 1844 { |
1845 str2[j++] = '\n'; | 1845 str2[j++] = '\n'; |
1846 } | 1846 } |
1847 /* Check for tags which begin CDATA and need to be closed */ | 1847 /* Check for tags which begin CDATA and need to be closed */ |
1848 #if 0 /* FIXME.. option is end tag optional, we can't handle this right now */ | 1848 #if 0 /* FIXME.. option is end tag optional, we can't handle this right now */ |
1849 else if (strncasecmp(str2 + i, "<option", 7) == 0) | 1849 else if (g_ascii_strncasecmp(str2 + i, "<option", 7) == 0) |
1850 { | 1850 { |
1851 /* FIXME: We should not do this if the OPTION is SELECT'd */ | 1851 /* FIXME: We should not do this if the OPTION is SELECT'd */ |
1852 cdata_close_tag = "</option>"; | 1852 cdata_close_tag = "</option>"; |
1853 } | 1853 } |
1854 #endif | 1854 #endif |
1855 else if (strncasecmp(str2 + i, "<script", 7) == 0) | 1855 else if (g_ascii_strncasecmp(str2 + i, "<script", 7) == 0) |
1856 { | 1856 { |
1857 cdata_close_tag = "</script>"; | 1857 cdata_close_tag = "</script>"; |
1858 } | 1858 } |
1859 else if (strncasecmp(str2 + i, "<style", 6) == 0) | 1859 else if (g_ascii_strncasecmp(str2 + i, "<style", 6) == 0) |
1860 { | 1860 { |
1861 cdata_close_tag = "</style>"; | 1861 cdata_close_tag = "</style>"; |
1862 } | 1862 } |
1863 /* Update the index and continue checking after the tag */ | 1863 /* Update the index and continue checking after the tag */ |
1864 i = (str2[k] == '<' || str2[k] == '\0')? k - 1: k; | 1864 i = (str2[k] == '<' || str2[k] == '\0')? k - 1: k; |
3077 | 3077 |
3078 /* Count how many times the delimiter appears */ | 3078 /* Count how many times the delimiter appears */ |
3079 i = 0; /* position in the source string */ | 3079 i = 0; /* position in the source string */ |
3080 j = 0; /* number of occurrences of "delimiter" */ | 3080 j = 0; /* number of occurrences of "delimiter" */ |
3081 while (string[i] != '\0') { | 3081 while (string[i] != '\0') { |
3082 if (!strncasecmp(&string[i], delimiter, length_del)) { | 3082 if (!g_ascii_strncasecmp(&string[i], delimiter, length_del)) { |
3083 i += length_del; | 3083 i += length_del; |
3084 j += length_rep; | 3084 j += length_rep; |
3085 } else { | 3085 } else { |
3086 i++; | 3086 i++; |
3087 j++; | 3087 j++; |
3091 ret = g_malloc(j+1); | 3091 ret = g_malloc(j+1); |
3092 | 3092 |
3093 i = 0; /* position in the source string */ | 3093 i = 0; /* position in the source string */ |
3094 j = 0; /* position in the destination string */ | 3094 j = 0; /* position in the destination string */ |
3095 while (string[i] != '\0') { | 3095 while (string[i] != '\0') { |
3096 if (!strncasecmp(&string[i], delimiter, length_del)) { | 3096 if (!g_ascii_strncasecmp(&string[i], delimiter, length_del)) { |
3097 strncpy(&ret[j], replacement, length_rep); | 3097 strncpy(&ret[j], replacement, length_rep); |
3098 i += length_del; | 3098 i += length_del; |
3099 j += length_rep; | 3099 j += length_rep; |
3100 } else { | 3100 } else { |
3101 ret[j] = string[i]; | 3101 ret[j] = string[i]; |