Simplified StringWrapper

- by changing intoStream to << overload
- and removing redundant ctor
This commit is contained in:
Phil Nash 2013-03-27 23:36:58 +00:00
parent b052bd729a
commit 9e8abc33e7
4 changed files with 13 additions and 21 deletions

View File

@ -161,7 +161,7 @@ namespace Catch {
displayedSpecificOption = true; displayedSpecificOption = true;
std::cout << "\n" << opt.optionNames() << " " << opt.argsSynopsis() << "\n\n" std::cout << "\n" << opt.optionNames() << " " << opt.argsSynopsis() << "\n\n"
<< opt.optionSummary() << "\n\n" << opt.optionSummary() << "\n\n"
<< LineWrapper().setIndent( 2 ).wrap( opt.optionDescription() ).toString() << "\n" << std::endl; << LineWrapper().setIndent( 2 ).wrap( opt.optionDescription() ) << "\n" << std::endl;
} }
} }

View File

@ -15,7 +15,6 @@ namespace Catch {
class LineWrapper { class LineWrapper {
public: public:
LineWrapper( std::size_t _indent, std::size_t _right );
LineWrapper( std::size_t _right ); LineWrapper( std::size_t _right );
LineWrapper(); LineWrapper();
@ -24,7 +23,6 @@ namespace Catch {
LineWrapper& wrap( std::string const& _str ); LineWrapper& wrap( std::string const& _str );
std::ostream& intoStream( std::ostream& stream ) const;
std::string toString() const; std::string toString() const;
typedef std::vector<std::string>::const_iterator const_iterator; typedef std::vector<std::string>::const_iterator const_iterator;
@ -32,6 +30,8 @@ namespace Catch {
const_iterator begin() const { return lines.begin(); } const_iterator begin() const { return lines.begin(); }
const_iterator end() const { return lines.end(); } const_iterator end() const { return lines.end(); }
friend std::ostream& operator << ( std::ostream& _stream, LineWrapper const& _lineWrapper );
private: private:
void wrapInternal( std::string const& _str ); void wrapInternal( std::string const& _str );
void addLine( const std::string& _line ); void addLine( const std::string& _line );

View File

@ -12,13 +12,6 @@
namespace Catch { namespace Catch {
LineWrapper::LineWrapper( std::size_t _indent, std::size_t _right )
: indent( _indent, ' ' ),
right( _right ),
nextTab( 0 ),
tab( 0 )
{}
LineWrapper::LineWrapper( std::size_t _right ) LineWrapper::LineWrapper( std::size_t _right )
: right( _right ), : right( _right ),
nextTab( 0 ), nextTab( 0 ),
@ -75,18 +68,18 @@ namespace Catch {
addLine( _str ); addLine( _str );
} }
std::ostream& LineWrapper::intoStream( std::ostream& stream ) const { std::ostream& operator << ( std::ostream& _stream, LineWrapper const& _lineWrapper ) {
for( const_iterator it = begin(), itEnd = end(); for( LineWrapper::const_iterator it = _lineWrapper.begin(), itEnd = _lineWrapper.end();
it != itEnd; ++it ) { it != itEnd; ++it ) {
if( it != begin() ) if( it != _lineWrapper.begin() )
stream << "\n"; _stream << "\n";
stream << *it; _stream << *it;
} }
return stream; return _stream;
} }
std::string LineWrapper::toString() const { std::string LineWrapper::toString() const {
std::ostringstream oss; std::ostringstream oss;
intoStream( oss ); oss << *this;
return oss.str(); return oss.str();
} }

View File

@ -211,7 +211,7 @@ namespace Catch {
if( result.hasExpandedExpression() ) { if( result.hasExpandedExpression() ) {
stream << "with expansion:\n"; stream << "with expansion:\n";
TextColour colourGuard( TextColour::ReconstructedExpression ); TextColour colourGuard( TextColour::ReconstructedExpression );
stream << LineWrapper().setIndent(2).wrap( result.getExpandedExpression() ).toString() << "\n"; stream << LineWrapper().setIndent(2).wrap( result.getExpandedExpression() ) << "\n";
} }
} }
void printMessage() const { void printMessage() const {
@ -220,8 +220,7 @@ namespace Catch {
for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end(); for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
it != itEnd; it != itEnd;
++it ) { ++it ) {
LineWrapper().setIndent(2).wrap( it->message ).intoStream( stream ); stream << LineWrapper().setIndent(2).wrap( it->message ) << "\n";
stream << "\n";
} }
} }
void printSourceInfo() const { void printSourceInfo() const {