diff options
| author | Phil Nash | 2017-07-20 19:42:06 +0100 |
|---|---|---|
| committer | Phil Nash | 2017-07-20 19:42:06 +0100 |
| commit | b2a4dfcda41c856c80ea6764373f7691d9e591d8 (patch) | |
| tree | 2db7fcc077220d98205d3ebb92641150249a612d /include | |
| parent | f0890dcdf89d305862d0ba3518752c4becb65773 (diff) | |
| download | catch3-b2a4dfcda41c856c80ea6764373f7691d9e591d8.tar.gz | |
Embedded version of Clara with TextFlow fix for embedded newlines
Diffstat (limited to 'include')
| -rw-r--r-- | include/external/clara.hpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/include/external/clara.hpp b/include/external/clara.hpp index 5a13080c..189e16e2 100644 --- a/include/external/clara.hpp +++ b/include/external/clara.hpp @@ -35,8 +35,7 @@ #endif -namespace Catch { namespace clara { namespace TextFlow -{ +namespace Catch { namespace clara { namespace TextFlow { inline auto isWhitespace( char c ) -> bool { static std::string chars = " \t\n\r"; @@ -68,6 +67,7 @@ namespace Catch { namespace clara { namespace TextFlow size_t m_pos = 0; size_t m_len = 0; + size_t m_end = 0; bool m_suffix = false; iterator( Column const& column, size_t stringIndex ) @@ -92,8 +92,12 @@ namespace Catch { namespace clara { namespace TextFlow m_suffix = false; auto width = m_column.m_width-indent(); - if( line().size() < m_pos + width ) { - m_len = line().size() - m_pos; + m_end = m_pos; + while( m_end < line().size() && line()[m_end] != '\n' ) + ++m_end; + + if( m_end < m_pos + width ) { + m_len = m_end - m_pos; } else { size_t len = width; @@ -131,15 +135,18 @@ namespace Catch { namespace clara { namespace TextFlow auto operator *() const -> std::string { assert( m_stringIndex < m_column.m_strings.size() ); - assert( m_pos < line().size() ); - if( m_pos + m_column.m_width < line().size() ) + assert( m_pos < m_end ); + if( m_pos + m_column.m_width < m_end ) return addIndentAndSuffix(line().substr(m_pos, m_len)); else - return addIndentAndSuffix(line().substr(m_pos)); + return addIndentAndSuffix(line().substr(m_pos, m_end - m_pos)); } auto operator ++() -> iterator& { m_pos += m_len; + if( m_pos < line().size() && line()[m_pos] == '\n' ) + m_pos += 1; + while( m_pos < line().size() && isWhitespace( line()[m_pos] ) ) ++m_pos; |