diff options
Diffstat (limited to 'src/cppunit/StringTools.cpp')
| -rw-r--r-- | src/cppunit/StringTools.cpp | 109 |
1 files changed, 54 insertions, 55 deletions
diff --git a/src/cppunit/StringTools.cpp b/src/cppunit/StringTools.cpp index 7dc50ea..46abd4a 100644 --- a/src/cppunit/StringTools.cpp +++ b/src/cppunit/StringTools.cpp @@ -2,79 +2,78 @@ #include <algorithm> -namespace CppUnit -{ +CPPUNIT_NS_BEGIN + -namespace StringTools +std::string +StringTools::toString( int value ) { + OStringStream stream; + stream << value; + return stream.str(); +} - std::string toString( int value ) - { - OStringStream stream; - stream << value; - return stream.str(); - } - std::string toString( double value ) - { - OStringStream stream; - stream << value; - return stream.str(); - } +std::string +StringTools::toString( double value ) +{ + OStringStream stream; + stream << value; + return stream.str(); +} - Strings split( const std::string &text, - char separator ) +StringTools::Strings +StringTools::split( const std::string &text, + char separator ) +{ + Strings splittedText; + + std::string::const_iterator itStart = text.begin(); + while ( !text.empty() ) { - Strings splittedText; + 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; + } - 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; +} - return splittedText; - } +std::string +StringTools::wrap( const std::string &text, + int wrapColumn ) +{ + const char lineBreak = '\n'; + Strings lines = split( text, lineBreak ); - std::string wrap( const std::string &text, - int wrapColumn ) + std::string wrapped; + for ( Strings::const_iterator it = lines.begin(); it != lines.end(); ++it ) { - const char lineBreak = '\n'; - Strings lines = split( text, lineBreak ); + if ( it != lines.begin() ) + wrapped += lineBreak; - std::string wrapped; - for ( Strings::const_iterator it = lines.begin(); it != lines.end(); ++it ) + const std::string &line = *it; + int index =0; + while ( index < line.length() ) { - if ( it != lines.begin() ) + std::string lineSlice( line.substr( index, wrapColumn ) ); + wrapped += lineSlice; + index += wrapColumn; + if ( index < line.length() ) wrapped += lineBreak; - - const std::string &line = *it; - 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; } - -} // namespace StringTools + return wrapped; +} -} // namespace CppUnit +CPPUNIT_NS_END |
