Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Refactored line wrapping in Text constructor a bit

Commit
97d99852a85f37dbc19fac9e6979c63bf5db0bc2
Author
Phil Nash ·
Parents
d37a8e8f9883

Files · Download .tar.gz

Changes

 include/internal/catch_text.h | 32 ++++++++++++++++----------------
 1 file 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(); }