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

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPhil Nash2017-07-20 19:42:06 +0100
committerPhil Nash2017-07-20 19:42:06 +0100
commitb2a4dfcda41c856c80ea6764373f7691d9e591d8 (patch)
tree2db7fcc077220d98205d3ebb92641150249a612d
parentf0890dcdf89d305862d0ba3518752c4becb65773 (diff)
downloadcatch3-b2a4dfcda41c856c80ea6764373f7691d9e591d8.tar.gz
Embedded version of Clara with TextFlow fix for embedded newlines
-rw-r--r--include/external/clara.hpp21
-rw-r--r--third_party/clara.hpp21
2 files changed, 28 insertions, 14 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;
diff --git a/third_party/clara.hpp b/third_party/clara.hpp
index 5d7f6f4e..0cd00b94 100644
--- a/third_party/clara.hpp
+++ b/third_party/clara.hpp
@@ -33,8 +33,7 @@
#endif
-namespace clara { namespace TextFlow
-{
+namespace clara { namespace TextFlow {
inline auto isWhitespace( char c ) -> bool {
static std::string chars = " \t\n\r";
@@ -66,6 +65,7 @@ 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 )
@@ -90,8 +90,12 @@ 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;
@@ -129,15 +133,18 @@ 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;