mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Typedef Column::iterator as Column::const_iterator not vice versa
This commit is contained in:
parent
2520ad4b6e
commit
455ae0c561
@ -39,7 +39,7 @@ namespace {
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace TextFlow {
|
namespace TextFlow {
|
||||||
|
|
||||||
void Column::iterator::calcLength() {
|
void Column::const_iterator::calcLength() {
|
||||||
m_suffix = false;
|
m_suffix = false;
|
||||||
auto width = m_column.m_width - indent();
|
auto width = m_column.m_width - indent();
|
||||||
m_end = m_pos;
|
m_end = m_pos;
|
||||||
@ -73,14 +73,14 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Column::iterator::indent() const {
|
size_t Column::const_iterator::indent() const {
|
||||||
auto initial =
|
auto initial =
|
||||||
m_pos == 0 ? m_column.m_initialIndent : std::string::npos;
|
m_pos == 0 ? m_column.m_initialIndent : std::string::npos;
|
||||||
return initial == std::string::npos ? m_column.m_indent : initial;
|
return initial == std::string::npos ? m_column.m_indent : initial;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
Column::iterator::addIndentAndSuffix( size_t position,
|
Column::const_iterator::addIndentAndSuffix( size_t position,
|
||||||
size_t length ) const {
|
size_t length ) const {
|
||||||
std::string ret;
|
std::string ret;
|
||||||
const auto desired_indent = indent();
|
const auto desired_indent = indent();
|
||||||
@ -94,7 +94,7 @@ namespace Catch {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Column::iterator::iterator( Column const& column ): m_column( column ) {
|
Column::const_iterator::const_iterator( Column const& column ): m_column( column ) {
|
||||||
assert( m_column.m_width > m_column.m_indent );
|
assert( m_column.m_width > m_column.m_indent );
|
||||||
assert( m_column.m_initialIndent == std::string::npos ||
|
assert( m_column.m_initialIndent == std::string::npos ||
|
||||||
m_column.m_width > m_column.m_initialIndent );
|
m_column.m_width > m_column.m_initialIndent );
|
||||||
@ -104,12 +104,12 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Column::iterator::operator*() const {
|
std::string Column::const_iterator::operator*() const {
|
||||||
assert( m_pos <= m_end );
|
assert( m_pos <= m_end );
|
||||||
return addIndentAndSuffix( m_pos, m_len );
|
return addIndentAndSuffix( m_pos, m_len );
|
||||||
}
|
}
|
||||||
|
|
||||||
Column::iterator& Column::iterator::operator++() {
|
Column::const_iterator& Column::const_iterator::operator++() {
|
||||||
m_pos += m_len;
|
m_pos += m_len;
|
||||||
std::string const& current_line = m_column.m_string;
|
std::string const& current_line = m_column.m_string;
|
||||||
if ( m_pos < current_line.size() && current_line[m_pos] == '\n' ) {
|
if ( m_pos < current_line.size() && current_line[m_pos] == '\n' ) {
|
||||||
@ -127,8 +127,8 @@ namespace Catch {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Column::iterator Column::iterator::operator++( int ) {
|
Column::const_iterator Column::const_iterator::operator++( int ) {
|
||||||
iterator prev( *this );
|
const_iterator prev( *this );
|
||||||
operator++();
|
operator++();
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace Catch {
|
|||||||
size_t m_initialIndent = std::string::npos;
|
size_t m_initialIndent = std::string::npos;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class iterator {
|
class const_iterator {
|
||||||
friend Column;
|
friend Column;
|
||||||
struct EndTag {};
|
struct EndTag {};
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ namespace Catch {
|
|||||||
size_t m_end = 0;
|
size_t m_end = 0;
|
||||||
bool m_suffix = false;
|
bool m_suffix = false;
|
||||||
|
|
||||||
iterator( Column const& column, EndTag ):
|
const_iterator( Column const& column, EndTag ):
|
||||||
m_column( column ), m_pos( m_column.m_string.size() ) {}
|
m_column( column ), m_pos( m_column.m_string.size() ) {}
|
||||||
|
|
||||||
void calcLength();
|
void calcLength();
|
||||||
@ -56,21 +56,21 @@ namespace Catch {
|
|||||||
using reference = value_type&;
|
using reference = value_type&;
|
||||||
using iterator_category = std::forward_iterator_tag;
|
using iterator_category = std::forward_iterator_tag;
|
||||||
|
|
||||||
explicit iterator( Column const& column );
|
explicit const_iterator( Column const& column );
|
||||||
|
|
||||||
std::string operator*() const;
|
std::string operator*() const;
|
||||||
|
|
||||||
iterator& operator++();
|
const_iterator& operator++();
|
||||||
iterator operator++( int );
|
const_iterator operator++( int );
|
||||||
|
|
||||||
bool operator==( iterator const& other ) const {
|
bool operator==( const_iterator const& other ) const {
|
||||||
return m_pos == other.m_pos && &m_column == &other.m_column;
|
return m_pos == other.m_pos && &m_column == &other.m_column;
|
||||||
}
|
}
|
||||||
bool operator!=( iterator const& other ) const {
|
bool operator!=( const_iterator const& other ) const {
|
||||||
return !operator==( other );
|
return !operator==( other );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
using const_iterator = iterator;
|
using iterator = const_iterator;
|
||||||
|
|
||||||
explicit Column( std::string const& text ): m_string( text ) {}
|
explicit Column( std::string const& text ): m_string( text ) {}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ namespace Catch {
|
|||||||
struct EndTag {};
|
struct EndTag {};
|
||||||
|
|
||||||
std::vector<Column> const& m_columns;
|
std::vector<Column> const& m_columns;
|
||||||
std::vector<Column::iterator> m_iterators;
|
std::vector<Column::const_iterator> m_iterators;
|
||||||
size_t m_activeIterators;
|
size_t m_activeIterators;
|
||||||
|
|
||||||
iterator( Columns const& columns, EndTag );
|
iterator( Columns const& columns, EndTag );
|
||||||
|
Loading…
Reference in New Issue
Block a user