Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Apr 9, 2024
1 parent dab5889 commit 7c586ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
41 changes: 22 additions & 19 deletions src/catch2/internal/catch_textflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,21 @@ namespace Catch {
void AnsiSkippingString::preprocessString() {
for ( auto it = m_string.begin(); it != m_string.end(); ) {
// try to read through an ansi sequence
while ( it != m_string.end() && *it == '\033' &&
it + 1 != m_string.end() && *( it + 1 ) == '[' ) {
while ( it + 1 < m_string.end() && *it == '\033' &&
*( it + 1 ) == '[' ) {
auto cursor = it + 2;
while ( cursor != m_string.end() &&
( isdigit( *cursor ) || *cursor == ';' ) ) {
++cursor;
}
if ( cursor != m_string.end() && *cursor == 'm' ) {
// 'm' -> 0xff
*cursor = AnsiSkippingString::sentinel;
// if we've read an ansi sequence, set the iterator and
// return to the top of the loop
it = cursor + 1;
} else {
if ( cursor == m_string.end() || *cursor != 'm' ) {
break;
}
// 'm' -> 0xff
*cursor = AnsiSkippingString::sentinel;
// if we've read an ansi sequence, set the iterator and
// return to the top of the loop
it = cursor + 1;
}
if ( it != m_string.end() ) {
++m_size;
Expand All @@ -62,6 +61,11 @@ namespace Catch {
preprocessString();
}

AnsiSkippingString::AnsiSkippingString( std::string&& text ):
m_string( CATCH_MOVE( text ) ) {
preprocessString();
}

AnsiSkippingString::const_iterator AnsiSkippingString::begin() const {
return const_iterator( m_string );
}
Expand Down Expand Up @@ -90,21 +94,20 @@ namespace Catch {
void AnsiSkippingString::const_iterator::tryParseAnsiEscapes() {
// check if we've landed on an ansi sequence, and if so read through
// it
while ( m_it != m_string->end() && *m_it == '\033' &&
m_it + 1 != m_string->end() && *( m_it + 1 ) == '[' ) {
while ( m_it + 1 < m_string->end() && *m_it == '\033' &&
*( m_it + 1 ) == '[' ) {
auto cursor = m_it + 2;
while ( cursor != m_string->end() &&
( isdigit( *cursor ) || *cursor == ';' ) ) {
++cursor;
}
if ( cursor != m_string->end() &&
*cursor == AnsiSkippingString::sentinel ) {
// if we've read an ansi sequence, set the iterator and
// return to the top of the loop
m_it = cursor + 1;
} else {
if ( cursor == m_string->end() ||
*cursor != AnsiSkippingString::sentinel ) {
break;
}
// if we've read an ansi sequence, set the iterator and
// return to the top of the loop
m_it = cursor + 1;
}
}

Expand Down Expand Up @@ -228,12 +231,12 @@ namespace Catch {
}

std::string Column::const_iterator::operator*() const {
// assert( m_lineStart <= m_parsedTo );
assert( m_lineStart != m_parsedTo );
return addIndentAndSuffix( m_lineStart, m_lineEnd );
}

Column::const_iterator& Column::const_iterator::operator++() {
m_lineStart = m_lineEnd; // FIXME
m_lineStart = m_lineEnd;
AnsiSkippingString const& current_line = m_column.m_string;
if ( m_lineStart != current_line.end() && *m_lineStart == '\n' ) {
m_lineStart++;
Expand Down
3 changes: 2 additions & 1 deletion src/catch2/internal/catch_textflow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ namespace Catch {
// constant value" warning on MSVC
static constexpr char sentinel = static_cast<char>( 0xffu );

AnsiSkippingString( std::string const& text );
explicit AnsiSkippingString( std::string const& text );
explicit AnsiSkippingString( std::string&& text );

const_iterator begin() const;
const_iterator end() const;
Expand Down

0 comments on commit 7c586ce

Please sign in to comment.