<?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[Kritik für URL Encoder erbeten]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>Ich habe anhand von Beispielen die ich im Netz gefunden habe einen kleinen URL Encoder geschrieben. Ich würde gerne wissen, ob das so korrekt ist (Da ich mich mit URLs nicht besonders auskenne) und ob man da noch etwas dran verbessern kann.</p>
<pre><code>#include &lt;cctype&gt;
#include &lt;iomanip&gt;
#include &lt;sstream&gt;
#include &lt;string&gt;

std::string url_encode(const std::string &amp;value) {
    std::ostringstream escaped;
    escaped.fill('0');
    escaped &lt;&lt; std::hex;

    for (char c : value) {
        if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
            escaped &lt;&lt; c;
        }
        else {
            escaped &lt;&lt; '%' &lt;&lt; std::setw(2) &lt;&lt; ((int) c) &lt;&lt; std::setw(0);
        }
    }
    return escaped.str();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/318730/kritik-für-url-encoder-erbeten</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Jul 2026 19:54:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/318730.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 Jul 2013 12:53:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 12:53:30 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>Ich habe anhand von Beispielen die ich im Netz gefunden habe einen kleinen URL Encoder geschrieben. Ich würde gerne wissen, ob das so korrekt ist (Da ich mich mit URLs nicht besonders auskenne) und ob man da noch etwas dran verbessern kann.</p>
<pre><code>#include &lt;cctype&gt;
#include &lt;iomanip&gt;
#include &lt;sstream&gt;
#include &lt;string&gt;

std::string url_encode(const std::string &amp;value) {
    std::ostringstream escaped;
    escaped.fill('0');
    escaped &lt;&lt; std::hex;

    for (char c : value) {
        if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
            escaped &lt;&lt; c;
        }
        else {
            escaped &lt;&lt; '%' &lt;&lt; std::setw(2) &lt;&lt; ((int) c) &lt;&lt; std::setw(0);
        }
    }
    return escaped.str();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2340858</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340858</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Wed, 24 Jul 2013 12:53:30 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 13:10:21 GMT]]></title><description><![CDATA[<p>Ist es sinnvoll, so etwas zu schreiben und es dem Forum vorzuwerfen, wenn man sich nicht auskennt? Z.B. wird '*' nicht berücksichtigt. Vorschlag: erstmal lesen: <a href="http://www.ietf.org/rfc/rfc3986.txt" rel="nofollow">http://www.ietf.org/rfc/rfc3986.txt</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340863</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340863</guid><dc:creator><![CDATA[ietf1]]></dc:creator><pubDate>Wed, 24 Jul 2013 13:10:21 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 13:15:50 GMT]]></title><description><![CDATA[<p>ietf1 schrieb:</p>
<blockquote>
<p>Ist es sinnvoll, so etwas zu schreiben und es dem Forum vorzuwerfen, wenn man sich nicht auskennt? Z.B. wird '*' nicht berücksichtigt. Vorschlag: erstmal lesen: <a href="http://www.ietf.org/rfc/rfc3986.txt" rel="nofollow">http://www.ietf.org/rfc/rfc3986.txt</a></p>
</blockquote>
<p>Ich habe mich durchaus etwas eingelesen weiß aber nicht, ob ich das richtig verstanden habe. Ich dachte ich müsste alle Zeichen encoden die nicht &quot;unreserved&quot; sind. Im Standard steht:</p>
<blockquote>
<p>unreserved = ALPHA / DIGIT / &quot;-&quot; / &quot;.&quot; / &quot;_&quot; / &quot;~&quot;</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2340864</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340864</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Wed, 24 Jul 2013 13:15:50 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 13:40:10 GMT]]></title><description><![CDATA[<p>Grundsätzlich denke ich, dass dein Code richtig ist. Nur ist ein stringstream hier fehl am Platz, denn du willst nicht abhängig von der eingestellten locale sein, da du ein Protokoll erfüllen musst. (Die Darstellung von Zahlen kann dadurch z.B. verändert werden). Abgesehen davon ist Stringstream relativ langsam.</p>
<pre><code class="language-cpp">std::string url_encode(const std::string &amp;value) {
  std::array&lt;bool, 256&gt; unreserved = []{
    std::array&lt;bool, 256&gt; a{{}};
    for (unsigned char c : &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~&quot;)
      a[c] = true;
    return a;
  }();
  std::string escaped;
  for (unsigned char c : value) {
    if (unreserved[c])
      escaped += c;
    else {
      escaped += '%';
      escaped += &quot;0123456789ABCDEF&quot;[(c/0xF)&amp;0xF];
      escaped += &quot;0123456789ABCDEF&quot;[(c&amp;0xF)];
    }
  }
  return escaped;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2340869</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340869</guid><dc:creator><![CDATA[encoder]]></dc:creator><pubDate>Wed, 24 Jul 2013 13:40:10 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 13:57:54 GMT]]></title><description><![CDATA[<p>Danke für den Vorschlag. Ich bin mir nicht sicher, ob ich die Zeilen 2 bis 7 richtig verstehe. Du erstellt eine Lookup-Table und initialisiert sie mit dem Rückgabewert einer Lambda Funktion?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340877</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340877</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Wed, 24 Jul 2013 13:57:54 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 14:02:37 GMT]]></title><description><![CDATA[<p>TNA schrieb:</p>
<blockquote>
<p>Danke für den Vorschlag. Ich bin mir nicht sicher, ob ich die Zeilen 2 bis 7 richtig verstehe. Du erstellt eine Lookup-Table und initialisiert sie mit dem Rückgabewert einer Lambda Funktion?</p>
</blockquote>
<p>Ja. Mir fällt gerade auf, dass ich ein static vor der Tabelle vergessen habe, dann würde sie nur einmal berechnet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340880</guid><dc:creator><![CDATA[encoder]]></dc:creator><pubDate>Wed, 24 Jul 2013 14:02:37 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 14:06:08 GMT]]></title><description><![CDATA[<p>Danke. Das hatte mich auch schon gewundert, dass das schnell sein soll. Ist es den Wirklich so, dass das anhängen an einen String besonder schnell ist? Muss da nicht sehr viel Speicher neu angefordert und kopiert werden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340882</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340882</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Wed, 24 Jul 2013 14:06:08 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 14:12:18 GMT]]></title><description><![CDATA[<p>Nein, std::string reserviert normalerweise exponentiell Speicher, heißt wenn du an einen String mit 64 Elementen eins dran hängst, und kein Platz mehr frei ist, reserviert er z.B. gleich 128 byte. Siehe auch .capacity() Kopiert werden muss natürlich. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340886</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340886</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Wed, 24 Jul 2013 14:12:18 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 14:29:57 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Nein, std::string reserviert normalerweise exponentiell Speicher, heißt wenn du an einen String mit 64 Elementen eins dran hängst, und kein Platz mehr frei ist, reserviert er z.B. gleich 128 byte. Siehe auch .capacity() Kopiert werden muss natürlich. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
</blockquote>
<p>Ich kenne das jetzt nur von std::vector. Die String Implementation von libcxx scheint das auch nicht zu machen wenn ich das richtig sehe: <a href="http://llvm.org/svn/llvm-project/libcxx/trunk/include/string" rel="nofollow">http://llvm.org/svn/llvm-project/libcxx/trunk/include/string</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340892</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Wed, 24 Jul 2013 14:29:57 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 14:30:19 GMT]]></title><description><![CDATA[<p>TNA schrieb:</p>
<blockquote>
<p>Die String Implementation von libcxx scheint das auch nicht zu machen wenn ich das richtig sehe: <a href="http://llvm.org/svn/llvm-project/libcxx/trunk/include/string" rel="nofollow">http://llvm.org/svn/llvm-project/libcxx/trunk/include/string</a></p>
</blockquote>
<p>Wo siehst du das? Ich sehe was anderes</p>
<pre><code class="language-cpp">// in: basic_string&lt;_CharT, _Traits, _Allocator&gt;::push_back(value_type __c)

    if (__sz == __cap)
    {
        __grow_by(__cap, 1, __sz, __sz, 0);
        __is_short = !__is_long();
    }
</code></pre>
<p>Heisst: &quot;Wenn neue size()==capacity(), mach capacity() += capacity()&quot;.</p>
<p>stringstream macht das genau gleich, nur hat der einen enormen Overhead pro operator&lt;&lt;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340894</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340894</guid><dc:creator><![CDATA[encoder]]></dc:creator><pubDate>Wed, 24 Jul 2013 14:30:19 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 14:38:05 GMT]]></title><description><![CDATA[<p>encoder schrieb:</p>
<blockquote>
<p>Wo siehst du das? Ich sehe was anderes</p>
</blockquote>
<p>Ups, ich hatte nicht berücksichtigt, dass du einen char anhängst und keinen String. Wäre es aber nicht trotzdem sinnvoll, ein</p>
<pre><code>escaped.reserve(value.size());
</code></pre>
<p>zu machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340898</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340898</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Wed, 24 Jul 2013 14:38:05 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 14:37:39 GMT]]></title><description><![CDATA[<p>Sorry, hab mich verguckt, es wird nur um 1 vergrössert. Scheint so, als wäre std::string da noch refcounted, also gar nicht mehr C++11-konform.</p>
<p>Dann nimm solange halt vector&lt;char&gt;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340899</guid><dc:creator><![CDATA[encoder]]></dc:creator><pubDate>Wed, 24 Jul 2013 14:37:39 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 14:58:11 GMT]]></title><description><![CDATA[<p>Soweit ich weiß wurde libcxx extra für c++11 designed und der string ist nicht refcounted. Mir ist allerdings noch die Idee gekommen, einfach am Anfang genug Speicher mit reserve() zu reservieren und nachher ein shrink_to_fit() zu machen. Würde da etwas gegen sprechen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340905</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Wed, 24 Jul 2013 14:58:11 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 15:01:17 GMT]]></title><description><![CDATA[<p>@encoder:</p>
<pre><code>static std::array&lt;bool, 256&gt; unreserved;

  if( !unreserved['A'] )
    for (unsigned char c : &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~&quot;) 
      unreserved[c] = true;
</code></pre>
<p>?</p>
<blockquote>
<p>infach am Anfang genug Speicher mit reserve() zu reservieren und nachher ein shrink_to_fit() zu machen. Würde da etwas gegen sprechen?</p>
</blockquote>
<p>Nein, genau so sind diese Funktionen gedacht, damit würde das hin- und her kopieren eliminiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340906</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340906</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Wed, 24 Jul 2013 15:01:17 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 15:05:56 GMT]]></title><description><![CDATA[<pre><code>std::string url_encode(const std::string &amp;value) { 
  static std::array&lt;bool, 256&gt; unreserved = []{ 
    std::array&lt;bool, 256&gt; a{{}}; 
    for (unsigned char c : &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~&quot;) 
      a[c] = true; 
    return a; 
  }(); 
  std::string escaped;
  escaped.reserve(value.size()*3);
  for (unsigned char c : value) { 
    if (unreserved[c]) 
      escaped += c; 
    else { 
      escaped += '%'; 
      escaped += &quot;0123456789ABCDEF&quot;[(c/0xF)&amp;0xF]; 
      escaped += &quot;0123456789ABCDEF&quot;[(c&amp;0xF)]; 
    } 
  }
  escaped.shrink_to_fit();
  return escaped; 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2340909</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340909</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Wed, 24 Jul 2013 15:05:56 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 15:57:38 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;array&gt;
#include &lt;bitset&gt;
#include &lt;cassert&gt;

std::string url_encode(const std::string &amp;value) {
  static std::array&lt;bool, 256&gt; unreserved = []{
    std::array&lt;bool, 256&gt; a{{}};
    for (unsigned char c : &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~&quot;)
      a[c] = true;
    return a;
  }();
  std::string escaped;
  escaped.reserve(value.size()*3);
  for (unsigned char c : value) {
    if (unreserved[c])
      escaped += c;
    else {
      escaped += '%';
      escaped += &quot;0123456789ABCDEF&quot;[(c/16)&amp;0xF]; //hier stand 15 statt 16
      escaped += &quot;0123456789ABCDEF&quot;[(c&amp;0xF)];
    }
  }
  escaped.shrink_to_fit();
  return escaped;
}

namespace generalized
{
	bool needs_escape(char c)
	{
		static std::bitset&lt;256&gt; const flags = []()
		{
			std::bitset&lt;256&gt; result;
			for (unsigned char c : &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~&quot;)
			{
				result.set(c);
			}
			return result;
		}();
		return ! flags.test(static_cast&lt;unsigned char&gt;(c));
	}

	template &lt;class OutputIterator&gt;
	OutputIterator escape(char c, OutputIterator dest)
	{
		*dest++ = '%';
		unsigned const uc = static_cast&lt;unsigned char&gt;(c);
		char const * const digits = &quot;0123456789ABCDEF&quot;;
		*dest++ = digits[uc / 16];
		*dest++ = digits[uc &amp; 15];
		return dest;
	}

	template &lt;class InputIterator, class OutputIterator&gt;
	OutputIterator
	url_encode(InputIterator source_begin,
			   InputIterator source_end,
			   OutputIterator dest)
	{
		for (; source_begin != source_end; ++source_begin)
		{
			char const c = *source_begin;
			if (needs_escape(c))
			{
				dest = escape(c, dest);
			}
			else
			{
				*dest++ = c;
			}
		}
		return dest;
	}

	template &lt;class InputIterator&gt;
	std::size_t size_when_encoded(InputIterator begin, InputIterator end)
	{
		std::size_t size = 0;
		for (; begin != end; ++begin)
		{
			if (needs_escape(*begin))
			{
				size += 3;
			}
			else
			{
				size += 1;
			}
		}
		return size;
	}

	///Fordert zuerst die mindestens benötigte Menge Speicher an und vergrößert
	///dann bei Bedarf mit string::push_back. Die Kapazität des Ergebnisses ist
	///möglicherweise höher als die Länge.
	std::string url_encode_to_string(std::string const &amp;value)
	{
		std::string encoded;
		encoded.reserve(value.size());
		url_encode(begin(value), end(value), std::back_inserter(encoded));
		return encoded;
	}

	///Berechnet die Länge des Ergebnisses und fordert genau so viel Speicher an.
	///Es gibt maximal eine dynamische Speicheranforderung.
	///Die Kapazität des Ergebnisses entspricht in der Regel der Länge.
	std::string url_encode_to_string_fit(std::string const &amp;value)
	{
		std::string encoded;
		encoded.resize(size_when_encoded(begin(value), end(value)));
		url_encode(begin(value), end(value), begin(encoded));
		return encoded;
	}
}

template &lt;class UrlEncode&gt;
void test_url_encode(UrlEncode const &amp;encode)
{
	assert(encode(&quot;&quot;) == &quot;&quot;);
	assert(encode(&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~&quot;) ==
	              &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~&quot;);
	assert(encode(&quot; \xff&quot;) == &quot;%20%FF&quot;);
}

int main()
{
	test_url_encode(url_encode);
	test_url_encode(generalized::url_encode_to_string);
	test_url_encode(generalized::url_encode_to_string_fit);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2340925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340925</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Wed, 24 Jul 2013 15:57:38 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Wed, 24 Jul 2013 18:05:33 GMT]]></title><description><![CDATA[<p>encoder schrieb:</p>
<blockquote>
<p>Sorry, hab mich verguckt, es wird nur um 1 vergrössert.</p>
</blockquote>
<p>Ich glaube du hast dich doppelt verguckt, so dass die ursprüngliche Aussage wieder stimmt:</p>
<pre><code class="language-cpp">template &lt;class _CharT, class _Traits, class _Allocator&gt;
void
basic_string&lt;_CharT, _Traits, _Allocator&gt;::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
                                                     size_type __n_copy,  size_type __n_del,     size_type __n_add)
{
    size_type __ms = max_size();
    if (__delta_cap &gt; __ms - __old_cap - 1)
        this-&gt;__throw_length_error();
    pointer __old_p = __get_pointer();
    size_type __cap = __old_cap &lt; __ms / 2 - __alignment ?             // vvvvvvvvvvvvv -- HIER
                          __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
                          __ms - 1;
    pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
    __invalidate_all_iterators();
    if (__n_copy != 0)
        traits_type::copy(_VSTD::__to_raw_pointer(__p),
                          _VSTD::__to_raw_pointer(__old_p), __n_copy);
    size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
    if (__sec_cp_sz != 0)
        traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
                          _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
                          __sec_cp_sz);
    if (__old_cap+1 != __min_cap)
        __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
    __set_long_pointer(__p);
    __set_long_cap(__cap+1);
}
</code></pre>
<p>Heisst: wenn <code>__old_cap</code> noch verdoppelt werden kann, dann wird immer mindestens verdoppelt. Und nur falls <code>__delta_cap &gt; __old_cap</code> spielt <code>__delta_cap</code> eine Rolle -- in dem Fall wird dann mehr als verdoppelt.</p>
<p>=&gt; Fragwürdiger name. <code>__min_grow_amount</code> wäre mMn. ein besserer Name. Hätte zumindest bei mir gleich den Verdacht geweckt dass vermutlich oft mehr &quot;gegrowd&quot; wird als man da übergibt.</p>
<p>encoder schrieb:</p>
<blockquote>
<p>Scheint so, als wäre std::string da noch refcounted, also gar nicht mehr C++11-konform.</p>
</blockquote>
<p>Wo scheint das so <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /><br />
Ich seh' da nur ne Small-String-Optimization.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2340968</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2340968</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Wed, 24 Jul 2013 18:05:33 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Thu, 25 Jul 2013 08:49:07 GMT]]></title><description><![CDATA[<p>Ich habe noch eine Frage zum Ausdruck</p>
<pre><code>(c/0xF)&amp;0xF
</code></pre>
<p>c/0xF ist doch ein &quot;trickreicher&quot; Rechtsshift oder? Warum ist das besser als x &gt;&gt; 4 ? Wozu muss man danach noch maskieren? Sollten in den ersten 4 Bits nicht ohnehin Nullen drin stehen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341059</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341059</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Thu, 25 Jul 2013 08:49:07 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Thu, 25 Jul 2013 10:01:51 GMT]]></title><description><![CDATA[<blockquote>
<p>c/0xF ist doch ein &quot;trickreicher&quot; Rechtsshift oder?</p>
</blockquote>
<p>Nein.<br />
<a href="http://ideone.com/YuHfoS" rel="nofollow">http://ideone.com/YuHfoS</a><br />
Also ich sehe nicht das selbe Bitmuster nur ein wenig weiter rechts....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341087</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341087</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Thu, 25 Jul 2013 10:01:51 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Thu, 25 Jul 2013 10:07:43 GMT]]></title><description><![CDATA[<p>TNA schrieb:</p>
<blockquote>
<p>Ich habe noch eine Frage zum Ausdruck</p>
<pre><code>(c/0xF)&amp;0xF
</code></pre>
<p>c/0xF ist doch ein &quot;trickreicher&quot; Rechtsshift oder? Warum ist das besser als x &gt;&gt; 4 ? Wozu muss man danach noch maskieren? Sollten in den ersten 4 Bits nicht ohnehin Nullen drin stehen?</p>
</blockquote>
<p>15 ist einfach die falsche Zahl. Es müsste 16 heißen, damit die Division einen Rechts-Shift um 4 bewirkt.<br />
Das Maskieren ist in der Tat überflüssig, wenn ein <code>char</code> genau 8 Bits hat oder die Werte unter 256 liegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341089</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341089</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Thu, 25 Jul 2013 10:07:43 GMT</pubDate></item><item><title><![CDATA[Reply to Kritik für URL Encoder erbeten on Thu, 25 Jul 2013 10:25:45 GMT]]></title><description><![CDATA[<p>TyRoXx schrieb:</p>
<blockquote>
<p>15 ist einfach die falsche Zahl. Es müsste 16 heißen, damit die Division einen Rechts-Shift um 4 bewirkt.</p>
</blockquote>
<p>Hätte mir auch auffallen sollen, dass das keine Zweierpotenz ist. Genau darum würde ich x &gt;&gt; 4 bevorzugen, weil man da sofort sieht was gemeint ist und der Compiler wahrscheinlich ohnehin den schnellstmöglichen Code generiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341097</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Thu, 25 Jul 2013 10:25:45 GMT</pubDate></item></channel></rss>