summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-06-01 08:48:42 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-06-01 09:24:28 (GMT)
commit2812bddd81f8a1b804c7460f4e14cd0aa393d129 (patch)
treed46294f35150c4f0f43deaf2d31fceaf945ae715 /3rdParty/CppUnit/src/StringTools.cpp
downloadswift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.zip
swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.tar.bz2
Import.
Diffstat (limited to '3rdParty/CppUnit/src/StringTools.cpp')
-rw-r--r--3rdParty/CppUnit/src/StringTools.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/3rdParty/CppUnit/src/StringTools.cpp b/3rdParty/CppUnit/src/StringTools.cpp
new file mode 100644
index 0000000..dc995d8
--- /dev/null
+++ b/3rdParty/CppUnit/src/StringTools.cpp
@@ -0,0 +1,80 @@
+#include <cppunit/tools/StringTools.h>
+#include <cppunit/portability/Stream.h>
+#include <algorithm>
+
+
+CPPUNIT_NS_BEGIN
+
+
+std::string
+StringTools::toString( int value )
+{
+ OStringStream stream;
+ stream << value;
+ return stream.str();
+}
+
+
+std::string
+StringTools::toString( double value )
+{
+ OStringStream stream;
+ stream << value;
+ return stream.str();
+}
+
+
+StringTools::Strings
+StringTools::split( const std::string &text,
+ char separator )
+{
+ Strings splittedText;
+
+ std::string::const_iterator itStart = text.begin();
+ while ( !text.empty() )
+ {
+ std::string::const_iterator itSeparator = std::find( itStart,
+ text.end(),
+ separator );
+ splittedText.push_back( text.substr( itStart - text.begin(),
+ itSeparator - itStart ) );
+ if ( itSeparator == text.end() )
+ break;
+ itStart = itSeparator +1;
+ }
+
+ return splittedText;
+}
+
+
+std::string
+StringTools::wrap( const std::string &text,
+ int wrapColumn )
+{
+ const char lineBreak = '\n';
+ Strings lines = split( text, lineBreak );
+
+ std::string wrapped;
+ for ( Strings::const_iterator it = lines.begin(); it != lines.end(); ++it )
+ {
+ if ( it != lines.begin() )
+ wrapped += lineBreak;
+
+ const std::string &line = *it;
+ unsigned int index =0;
+ while ( index < line.length() )
+ {
+ std::string lineSlice( line.substr( index, wrapColumn ) );
+ wrapped += lineSlice;
+ index += wrapColumn;
+ if ( index < line.length() )
+ wrapped += lineBreak;
+ }
+ }
+
+ return wrapped;
+}
+
+
+CPPUNIT_NS_END
+