Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPhil Nash2013-04-20 18:41:00 +0100
committerPhil Nash2013-04-20 18:41:00 +0100
commit97d99852a85f37dbc19fac9e6979c63bf5db0bc2 (patch)
treefc08b0fa4863b0c823f2919fa9f3257d0be30282
parentd37a8e8f9883b3fbaada083f5543fcc96fdd6374 (diff)
downloadcatch3-97d99852a85f37dbc19fac9e6979c63bf5db0bc2.tar.gz
Refactored line wrapping in Text constructor a bit
-rw-r--r--include/internal/catch_text.h32
1 files changed, 16 insertions, 16 deletions
diff --git a/include/internal/catch_text.h b/include/internal/catch_text.h
index 7adcaa3b..97288a72 100644
--- a/include/internal/catch_text.h
+++ b/include/internal/catch_text.h
@@ -42,6 +42,7 @@ namespace Catch {
? _attr.initialIndent
: _attr.indent;
std::string remainder = _str;
+
while( !remainder.empty() ) {
assert( lines.size() < 1000 );
std::size_t tabPos = std::string::npos;
@@ -57,40 +58,39 @@ namespace Catch {
width--;
remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
}
+
if( width == remainder.size() ) {
- addLine( indent, remainder );
- remainder = std::string();
+ spliceLine( indent, remainder, width );
}
else if( remainder[width] == '\n' ) {
- addLine( indent, remainder.substr( 0, width ) );
+ spliceLine( indent, remainder, width );
+ if( width <= 1 || remainder.size() != 1 )
+ remainder = remainder.substr( 1 );
indent = _attr.indent;
- if( width > 1 && width == remainder.size()-1 )
- remainder = remainder.substr( width );
- else
- remainder = remainder.substr( width+1 );
}
else {
pos = remainder.find_last_of( wrappableChars, width );
if( pos != std::string::npos ) {
- addLine( indent, remainder.substr( 0, pos ) );
- if( remainder[pos] == ' ' )
- pos++;
- remainder = remainder.substr( pos );
+ spliceLine( indent, remainder, pos );
+ if( remainder[0] == ' ' )
+ remainder = remainder.substr( 1 );
}
else {
- addLine( indent, remainder.substr( 0, width-1 ) + "-" );
- remainder = remainder.substr( width-1 );
+ spliceLine( indent, remainder, width-1 );
+ lines.back() += "-";
}
if( lines.size() == 1 )
indent = _attr.indent;
if( tabPos != std::string::npos )
indent += tabPos;
}
- };
+ }
}
- void addLine( std::size_t indent, std::string const& _line ) {
- lines.push_back( std::string( indent, ' ' ) + _line );
+ void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
+ lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
+ _remainder = _remainder.substr( _pos );
}
+
typedef std::vector<std::string>::const_iterator const_iterator;
const_iterator begin() const { return lines.begin(); }