<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[URL-Decode Funktion richtig?]]></title><description><![CDATA[<p>Hi,<br />
ich brauche eine Funktion die eine hex-codierte URL dekodiert.</p>
<p>Aus Hallo%20Welt soll Hallo Welt werden.</p>
<p>Im Code eines Webservers habe ich dann das gefunden:</p>
<pre><code class="language-cpp">static void strdecode( char* to, char* from )
    {
    for ( ; *from != '\0'; ++to, ++from )
	{
	if ( from[0] == '%' &amp;&amp; isxdigit( from[1] ) &amp;&amp; isxdigit( from[2] ) )
	    {
	    *to = hexit( from[1] ) * 16 + hexit( from[2] );
	    from += 2;
	    }
	else
	    *to = *from;
	}
    *to = '\0';
    }
</code></pre>
<p>Nur bei dieser Funktion habe ich das Gefühl das sie falsch ist, wenn nach dem % keine Zeichen mehr kommen greift er trotzdem auf die nächsten beiden Zeichen zu, oder?</p>
<p>Als ich das kompiliert hab und Hallo% übergeben habe ist es aber nicht abgestürzt. Fängt die Funktion das doch irgendwo ab?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/122247/url-decode-funktion-richtig</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 01:38:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/122247.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 02 Oct 2005 14:15:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to URL-Decode Funktion richtig? on Sun, 02 Oct 2005 14:15:33 GMT]]></title><description><![CDATA[<p>Hi,<br />
ich brauche eine Funktion die eine hex-codierte URL dekodiert.</p>
<p>Aus Hallo%20Welt soll Hallo Welt werden.</p>
<p>Im Code eines Webservers habe ich dann das gefunden:</p>
<pre><code class="language-cpp">static void strdecode( char* to, char* from )
    {
    for ( ; *from != '\0'; ++to, ++from )
	{
	if ( from[0] == '%' &amp;&amp; isxdigit( from[1] ) &amp;&amp; isxdigit( from[2] ) )
	    {
	    *to = hexit( from[1] ) * 16 + hexit( from[2] );
	    from += 2;
	    }
	else
	    *to = *from;
	}
    *to = '\0';
    }
</code></pre>
<p>Nur bei dieser Funktion habe ich das Gefühl das sie falsch ist, wenn nach dem % keine Zeichen mehr kommen greift er trotzdem auf die nächsten beiden Zeichen zu, oder?</p>
<p>Als ich das kompiliert hab und Hallo% übergeben habe ist es aber nicht abgestürzt. Fängt die Funktion das doch irgendwo ab?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/884594</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/884594</guid><dc:creator><![CDATA[httpd]]></dc:creator><pubDate>Sun, 02 Oct 2005 14:15:33 GMT</pubDate></item><item><title><![CDATA[Reply to URL-Decode Funktion richtig? on Sun, 02 Oct 2005 14:24:01 GMT]]></title><description><![CDATA[<p>Hier wird es abgefangt:</p>
<pre><code class="language-cpp">// Annahme: from = &quot;%&quot;; // [0: '%'] [1: '\0'] [2: Access denied]
// from[0] == '%' -&gt; Ja, weiter
// isxdigit(from[1]) -&gt; Nein, da '\0', Abbruch
 if ( from[0] == '%' &amp;&amp; isxdigit( from[1] ) &amp;&amp; isxdigit( from[2] ) )
</code></pre>
<p>Die letzte Anweisung die einen Speicherzugriffsfehler bringen würde wird gar nicht mehr ausgeführt (garantiert).</p>
<p>MfG SideWinder</p>
]]></description><link>https://www.c-plusplus.net/forum/post/884600</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/884600</guid><dc:creator><![CDATA[SideWinder]]></dc:creator><pubDate>Sun, 02 Oct 2005 14:24:01 GMT</pubDate></item><item><title><![CDATA[Reply to URL-Decode Funktion richtig? on Tue, 04 Oct 2005 20:08:31 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">int convertHexDigitToDecimalNumber(char hexDigit)
{
	assert(isxdigit(hexDigit));

	switch(hexDigit)
	{
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
		return hexDigit - '0';
	case 'A':
	case 'B':
	case 'C':
	case 'D':
	case 'E':
	case 'F':
		return hexDigit - 'A' + 10;
	case 'a':
	case 'b':
	case 'c':
	case 'd':
	case 'e':
	case 'f':
		return hexDigit - 'a' + 10;
	}

	assert(false); // should never happen
	return 0;
}

bool convertTwoDigitHexStringToChar(const std::string&amp; input, unsigned char&amp; output)
{
	if(input.length() != 2)
	{
		return false;
	}

	if(!isxdigit(input[0]) || !isxdigit(input[1]))
	{
		return false;
	}

	output = convertHexDigitToDecimalNumber(input[0]) * 16;
	output += convertHexDigitToDecimalNumber(input[1]);

	return true;
}

std::string decodeURL(const std::string&amp; input)
{
	std::string output;
	unsigned char decodedCharacter;

	for(size_t i = 0; i &lt; input.length(); ++i)
	{
		if(input[i] == '%' &amp;&amp; convertTwoDigitHexStringToChar(input.substr(i + 1, 2), decodedCharacter))
		{
			output += decodedCharacter;
			i += 2;
		}
		else if(input[i] == '+')
		{
			output += ' ';
		}
		else
		{
			output += input[i];
		}
	}

	return output;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/885156</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/885156</guid><dc:creator><![CDATA[code.]]></dc:creator><pubDate>Tue, 04 Oct 2005 20:08:31 GMT</pubDate></item></channel></rss>