<?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[BOOST-Coderefeactoring (:]]></title><description><![CDATA[<p>Hallo,<br />
habe hier mal was programmiert. Ich wollte einfach mal ein bisschen testen was mit boost::algorithm und boost::tokenizer möglich ist. Allerdings bin ich mit verschiedenen Dingen nicht einverstanden und hätte gerne gewusst wie man solche Dinge besser löst. Erstmal der Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;boost/bind.hpp&gt;
#include &lt;boost/scoped_ptr.hpp&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;
#include &lt;boost/algorithm/string.hpp&gt; 
#include &lt;locale&gt; 
#include &lt;clocale&gt; 
#include &lt;boost/function.hpp&gt; 
#include &lt;boost/tokenizer.hpp&gt; 

class StringProcessor
{
	private:
		typedef boost::tokenizer&lt;boost::char_separator&lt;char&gt;&gt; Tokenizer; 

	private:
		boost::scoped_ptr&lt;std::string&gt; m_TextBuffer; /// Main string
		const std::vector&lt;std::string&gt; vec_TextBuffer; /// Vector with main strings
		boost::scoped_ptr&lt;Tokenizer&gt; m_Tokenizer; /// Main tokenizer

	public:
		///// Only get the cultural-information /////
		StringProcessor(const std::string &amp;CulturalCircle) :
			m_TextBuffer(new std::string(&quot;&quot;))
		{ 
			std::setlocale(LC_ALL, CulturalCircle.c_str()); /// Sets the cultural circle 
		}

		///// Get std::string by reference /////
	    StringProcessor(const std::string &amp;TextBuffer, const std::string &amp;CulturalCircle) :
			m_TextBuffer(new std::string(TextBuffer)) ,
			m_Tokenizer(new Tokenizer(TextBuffer))
		{ 
			std::setlocale(LC_ALL, CulturalCircle.c_str()); /// Sets the cultural circle 
		}

		///// Get std::string by std::vector /////
		StringProcessor(const std::vector&lt;std::string&gt; &amp;TextBuffer, const std::string &amp;CulturalCircle) :
			m_TextBuffer(new std::string) ,
			vec_TextBuffer(TextBuffer)
		{
			std::setlocale(LC_ALL, CulturalCircle.c_str()); /// Sets the global cultural circle
			std::vector&lt;std::string&gt;::const_iterator it(TextBuffer.begin());

			for(; it != TextBuffer.end(); ++it)
				*m_TextBuffer += *it;

			m_Tokenizer.reset(new Tokenizer(*m_TextBuffer)); 

			PrintConverts();
		}

		void PrintConverts() const;
};

void StringProcessor::PrintConverts() const
{
	std::vector&lt;std::string&gt; TextBuffer;
	std::string::const_iterator itBegin(m_TextBuffer-&gt;begin());
	unsigned int TextBufInkr(0);

	/*///// Normal string algorithm from BOOST /////*/

	///// Split the string on every whitespace into a vector /////
	boost::algorithm::split(TextBuffer, *m_TextBuffer, boost::algorithm::is_space());

	if((*itBegin == ' ') &amp;&amp; ((*m_TextBuffer)[m_TextBuffer-&gt;size()] == ' '))
	{
		///// Trims the std::string from the left and right /////
		std::cout&lt;&lt; &quot;=====Deletes the first and last whitespace=====&quot; &lt;&lt;std::endl;
		boost::algorithm::trim_left_copy(*m_TextBuffer);
		std::cout&lt;&lt; boost::algorithm::trim_right_copy(*m_TextBuffer) &lt;&lt;std::endl;
		std::cout&lt;&lt; &quot;=====Deletes the first and last whitespace=====&quot; &lt;&lt;std::endl;
	}
	else if(*itBegin == ' ')
	{
		///// Trims the std::string from the left /////
		std::cout&lt;&lt; &quot;=====Deletes the first whitespace=====&quot; &lt;&lt;std::endl;
		std::cout&lt;&lt; boost::algorithm::trim_left_copy(*m_TextBuffer) &lt;&lt;std::endl;
		std::cout&lt;&lt; &quot;=====/Deletes the first whitespace=====&quot; &lt;&lt;std::endl;
	}
	else if( ((*m_TextBuffer)[m_TextBuffer-&gt;size()] == ' '))
	{
		///// Trims the std::string from the right /////
		std::cout&lt;&lt; &quot;=====Deletes the last whitespace=====&quot; &lt;&lt;std::endl;
		boost::algorithm::trim_right_copy(*m_TextBuffer);
		std::cout&lt;&lt; &quot;=====/Deletes the last whitespace=====&quot; &lt;&lt;std::endl;
	}

	if(!vec_TextBuffer.empty())
	{
		///// Marks every white space /////
		std::cout&lt;&lt; &quot;=====Whitespaces Tracker=====&quot; &lt;&lt;std::endl;
		std::cout&lt;&lt; boost::algorithm::join(vec_TextBuffer, &quot;[whitespace] &quot;) &lt;&lt;std::endl; 
		std::cout&lt;&lt; &quot;=====/Whitespaces Tracker=====&quot; &lt;&lt;std::endl;
	}

	/*///// Tokenizer algorithm /////*/
	///// Interprets the token /////
	for(Tokenizer::iterator it(m_Tokenizer-&gt;begin());
		it != m_Tokenizer-&gt;end();
		++it, TextBufInkr++) 
			std::cout&lt;&lt; &quot;[&quot; &lt;&lt; TextBufInkr &lt;&lt;&quot;. Token]&quot; &lt;&lt; *it &lt;&lt;std::endl;
}

int main()
{
	std::vector&lt;std::string&gt; TestVector;
	TestVector.push_back(&quot; Hallo, &quot;);
	TestVector.push_back(&quot;mein Name ist &quot;);
	TestVector.push_back(&quot;Häbbärt! &quot;);

	StringProcessor strproc(TestVector, &quot;German&quot;);

	std::cin.get();
};
</code></pre>
<p>Zeilen die mir Sorgen machen:<br />
-19: Wie besser lösen?<br />
-105: Hier gibt es eine Assertion (&quot;(unsigned)(c + 1) &lt;= 256&quot;). Warum?</p>
<p>Ansonsten:<br />
Der Sinn der einzelnen Ctors soll erstmal nicht im Vordergrund stehen. Fände es toll wenn einer einfach mal sagt was er nicht so toll findet und sogar begründen könnte.</p>
<p>Danke! :xmas1: :xmas2:</p>
<p>EDIT: Wth!? Bin ich jetzt doof oder funktionieren die Codetags nicht!?<br />
EDIT²: Jeah, pumuckl ist der king.<br />
EDIT³: *push*</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/256158/boost-coderefeactoring</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 17:25:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/256158.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 08 Dec 2009 22:44:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to BOOST-Coderefeactoring (: on Wed, 09 Dec 2009 14:58:27 GMT]]></title><description><![CDATA[<p>Hallo,<br />
habe hier mal was programmiert. Ich wollte einfach mal ein bisschen testen was mit boost::algorithm und boost::tokenizer möglich ist. Allerdings bin ich mit verschiedenen Dingen nicht einverstanden und hätte gerne gewusst wie man solche Dinge besser löst. Erstmal der Code:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;boost/bind.hpp&gt;
#include &lt;boost/scoped_ptr.hpp&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;
#include &lt;boost/algorithm/string.hpp&gt; 
#include &lt;locale&gt; 
#include &lt;clocale&gt; 
#include &lt;boost/function.hpp&gt; 
#include &lt;boost/tokenizer.hpp&gt; 

class StringProcessor
{
	private:
		typedef boost::tokenizer&lt;boost::char_separator&lt;char&gt;&gt; Tokenizer; 

	private:
		boost::scoped_ptr&lt;std::string&gt; m_TextBuffer; /// Main string
		const std::vector&lt;std::string&gt; vec_TextBuffer; /// Vector with main strings
		boost::scoped_ptr&lt;Tokenizer&gt; m_Tokenizer; /// Main tokenizer

	public:
		///// Only get the cultural-information /////
		StringProcessor(const std::string &amp;CulturalCircle) :
			m_TextBuffer(new std::string(&quot;&quot;))
		{ 
			std::setlocale(LC_ALL, CulturalCircle.c_str()); /// Sets the cultural circle 
		}

		///// Get std::string by reference /////
	    StringProcessor(const std::string &amp;TextBuffer, const std::string &amp;CulturalCircle) :
			m_TextBuffer(new std::string(TextBuffer)) ,
			m_Tokenizer(new Tokenizer(TextBuffer))
		{ 
			std::setlocale(LC_ALL, CulturalCircle.c_str()); /// Sets the cultural circle 
		}

		///// Get std::string by std::vector /////
		StringProcessor(const std::vector&lt;std::string&gt; &amp;TextBuffer, const std::string &amp;CulturalCircle) :
			m_TextBuffer(new std::string) ,
			vec_TextBuffer(TextBuffer)
		{
			std::setlocale(LC_ALL, CulturalCircle.c_str()); /// Sets the global cultural circle
			std::vector&lt;std::string&gt;::const_iterator it(TextBuffer.begin());

			for(; it != TextBuffer.end(); ++it)
				*m_TextBuffer += *it;

			m_Tokenizer.reset(new Tokenizer(*m_TextBuffer)); 

			PrintConverts();
		}

		void PrintConverts() const;
};

void StringProcessor::PrintConverts() const
{
	std::vector&lt;std::string&gt; TextBuffer;
	std::string::const_iterator itBegin(m_TextBuffer-&gt;begin());
	unsigned int TextBufInkr(0);

	/*///// Normal string algorithm from BOOST /////*/

	///// Split the string on every whitespace into a vector /////
	boost::algorithm::split(TextBuffer, *m_TextBuffer, boost::algorithm::is_space());

	if((*itBegin == ' ') &amp;&amp; ((*m_TextBuffer)[m_TextBuffer-&gt;size()] == ' '))
	{
		///// Trims the std::string from the left and right /////
		std::cout&lt;&lt; &quot;=====Deletes the first and last whitespace=====&quot; &lt;&lt;std::endl;
		boost::algorithm::trim_left_copy(*m_TextBuffer);
		std::cout&lt;&lt; boost::algorithm::trim_right_copy(*m_TextBuffer) &lt;&lt;std::endl;
		std::cout&lt;&lt; &quot;=====Deletes the first and last whitespace=====&quot; &lt;&lt;std::endl;
	}
	else if(*itBegin == ' ')
	{
		///// Trims the std::string from the left /////
		std::cout&lt;&lt; &quot;=====Deletes the first whitespace=====&quot; &lt;&lt;std::endl;
		std::cout&lt;&lt; boost::algorithm::trim_left_copy(*m_TextBuffer) &lt;&lt;std::endl;
		std::cout&lt;&lt; &quot;=====/Deletes the first whitespace=====&quot; &lt;&lt;std::endl;
	}
	else if( ((*m_TextBuffer)[m_TextBuffer-&gt;size()] == ' '))
	{
		///// Trims the std::string from the right /////
		std::cout&lt;&lt; &quot;=====Deletes the last whitespace=====&quot; &lt;&lt;std::endl;
		boost::algorithm::trim_right_copy(*m_TextBuffer);
		std::cout&lt;&lt; &quot;=====/Deletes the last whitespace=====&quot; &lt;&lt;std::endl;
	}

	if(!vec_TextBuffer.empty())
	{
		///// Marks every white space /////
		std::cout&lt;&lt; &quot;=====Whitespaces Tracker=====&quot; &lt;&lt;std::endl;
		std::cout&lt;&lt; boost::algorithm::join(vec_TextBuffer, &quot;[whitespace] &quot;) &lt;&lt;std::endl; 
		std::cout&lt;&lt; &quot;=====/Whitespaces Tracker=====&quot; &lt;&lt;std::endl;
	}

	/*///// Tokenizer algorithm /////*/
	///// Interprets the token /////
	for(Tokenizer::iterator it(m_Tokenizer-&gt;begin());
		it != m_Tokenizer-&gt;end();
		++it, TextBufInkr++) 
			std::cout&lt;&lt; &quot;[&quot; &lt;&lt; TextBufInkr &lt;&lt;&quot;. Token]&quot; &lt;&lt; *it &lt;&lt;std::endl;
}

int main()
{
	std::vector&lt;std::string&gt; TestVector;
	TestVector.push_back(&quot; Hallo, &quot;);
	TestVector.push_back(&quot;mein Name ist &quot;);
	TestVector.push_back(&quot;Häbbärt! &quot;);

	StringProcessor strproc(TestVector, &quot;German&quot;);

	std::cin.get();
};
</code></pre>
<p>Zeilen die mir Sorgen machen:<br />
-19: Wie besser lösen?<br />
-105: Hier gibt es eine Assertion (&quot;(unsigned)(c + 1) &lt;= 256&quot;). Warum?</p>
<p>Ansonsten:<br />
Der Sinn der einzelnen Ctors soll erstmal nicht im Vordergrund stehen. Fände es toll wenn einer einfach mal sagt was er nicht so toll findet und sogar begründen könnte.</p>
<p>Danke! :xmas1: :xmas2:</p>
<p>EDIT: Wth!? Bin ich jetzt doof oder funktionieren die Codetags nicht!?<br />
EDIT²: Jeah, pumuckl ist der king.<br />
EDIT³: *push*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1819879</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1819879</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Wed, 09 Dec 2009 14:58:27 GMT</pubDate></item><item><title><![CDATA[Reply to BOOST-Coderefeactoring (: on Tue, 08 Dec 2009 23:38:01 GMT]]></title><description><![CDATA[<p>das liegt an deinen [deletes...][/deletes...] pseudo-BB-tags, damit kommt der parser wohl nicht ganz klar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1819886</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1819886</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Tue, 08 Dec 2009 23:38:01 GMT</pubDate></item></channel></rss>