MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlURIEscape

Function xmlURIEscape

ThirdParty/libxml2/vtklibxml2/uri.c:1748–1864  ·  view source on GitHub ↗

* xmlURIEscape: * @str: the string of the URI to escape * * Escaping routine, does not do validity checks ! * It will try to escape the chars needing this, but this is heuristic * based it's impossible to be sure. * * Returns an copy of the string, but escaped * * 25 May 2001 * Uses xmlParseURI and xmlURIEscapeStr to try to escape correctly * according to RFC2396. * - Carl Douglas

Source from the content-addressed store, hash-verified

1746 * - Carl Douglas
1747 */
1748xmlChar *
1749xmlURIEscape(const xmlChar * str)
1750{
1751 xmlChar *ret, *segment = NULL;
1752 xmlURIPtr uri;
1753 int ret2;
1754
1755 if (str == NULL)
1756 return (NULL);
1757
1758 uri = xmlCreateURI();
1759 if (uri != NULL) {
1760 /*
1761 * Allow escaping errors in the unescaped form
1762 */
1763 uri->cleanup = XML_URI_ALLOW_UNWISE;
1764 ret2 = xmlParseURIReference(uri, (const char *)str);
1765 if (ret2) {
1766 xmlFreeURI(uri);
1767 return (NULL);
1768 }
1769 }
1770
1771 if (!uri)
1772 return NULL;
1773
1774 ret = NULL;
1775
1776#define NULLCHK(p) if(!p) { \
1777 xmlFreeURI(uri); \
1778 xmlFree(ret); \
1779 return NULL; } \
1780
1781 if (uri->scheme) {
1782 segment = xmlURIEscapeStr(BAD_CAST uri->scheme, BAD_CAST "+-.");
1783 NULLCHK(segment)
1784 ret = xmlStrcat(ret, segment);
1785 ret = xmlStrcat(ret, BAD_CAST ":");
1786 xmlFree(segment);
1787 }
1788
1789 if (uri->authority) {
1790 segment =
1791 xmlURIEscapeStr(BAD_CAST uri->authority, BAD_CAST "/?;:@");
1792 NULLCHK(segment)
1793 ret = xmlStrcat(ret, BAD_CAST "//");
1794 ret = xmlStrcat(ret, segment);
1795 xmlFree(segment);
1796 }
1797
1798 if (uri->user) {
1799 segment = xmlURIEscapeStr(BAD_CAST uri->user, BAD_CAST ";:&=+$,");
1800 NULLCHK(segment)
1801 ret = xmlStrcat(ret,BAD_CAST "//");
1802 ret = xmlStrcat(ret, segment);
1803 ret = xmlStrcat(ret, BAD_CAST "@");
1804 xmlFree(segment);
1805 }

Callers

nothing calls this directly

Calls 5

xmlCreateURIFunction · 0.85
xmlParseURIReferenceFunction · 0.85
xmlFreeURIFunction · 0.85
xmlURIEscapeStrFunction · 0.85
xmlStrcatFunction · 0.85

Tested by

no test coverage detected