2011-10-18 02:05:06 +04:00
|
|
|
#ifndef buffer_iterator_inl_h_INCLUDED
|
|
|
|
#define buffer_iterator_inl_h_INCLUDED
|
|
|
|
|
|
|
|
#include "assert.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-03-30 15:37:18 +04:00
|
|
|
inline BufferIterator::BufferIterator(const Buffer& buffer, BufferCoord coord)
|
|
|
|
: m_buffer(&buffer), m_coord(coord)
|
2011-10-18 02:05:06 +04:00
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(is_valid());
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const Buffer& BufferIterator::buffer() const
|
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer);
|
2011-10-18 02:05:06 +04:00
|
|
|
return *m_buffer;
|
|
|
|
}
|
|
|
|
|
2011-10-24 18:26:21 +04:00
|
|
|
inline bool BufferIterator::is_valid() const
|
|
|
|
{
|
2013-04-23 20:46:18 +04:00
|
|
|
return m_buffer and m_buffer->is_valid(m_coord);
|
2011-10-24 18:26:21 +04:00
|
|
|
}
|
|
|
|
|
2012-08-15 20:18:12 +04:00
|
|
|
inline void BufferIterator::clamp(bool avoid_eol)
|
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer);
|
2012-08-15 20:18:12 +04:00
|
|
|
m_coord = m_buffer->clamp(m_coord, avoid_eol);
|
|
|
|
}
|
|
|
|
|
2011-10-18 02:05:06 +04:00
|
|
|
inline bool BufferIterator::operator==(const BufferIterator& iterator) const
|
|
|
|
{
|
2013-04-09 16:28:03 +04:00
|
|
|
return (m_buffer == iterator.m_buffer and m_coord == iterator.m_coord);
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BufferIterator::operator!=(const BufferIterator& iterator) const
|
|
|
|
{
|
2013-04-09 16:28:03 +04:00
|
|
|
return (m_buffer != iterator.m_buffer or m_coord != iterator.m_coord);
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BufferIterator::operator<(const BufferIterator& iterator) const
|
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer == iterator.m_buffer);
|
2012-03-30 15:37:18 +04:00
|
|
|
return (m_coord < iterator.m_coord);
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BufferIterator::operator<=(const BufferIterator& iterator) const
|
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer == iterator.m_buffer);
|
2012-03-30 15:37:18 +04:00
|
|
|
return (m_coord <= iterator.m_coord);
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BufferIterator::operator>(const BufferIterator& iterator) const
|
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer == iterator.m_buffer);
|
2012-03-30 15:37:18 +04:00
|
|
|
return (m_coord > iterator.m_coord);
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BufferIterator::operator>=(const BufferIterator& iterator) const
|
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer == iterator.m_buffer);
|
2012-03-30 15:37:18 +04:00
|
|
|
return (m_coord >= iterator.m_coord);
|
|
|
|
}
|
|
|
|
|
2012-10-01 22:20:08 +04:00
|
|
|
inline char BufferIterator::operator*() const
|
2011-10-18 02:05:06 +04:00
|
|
|
{
|
2012-12-13 17:34:33 +04:00
|
|
|
return m_buffer->m_lines[m_coord.line].content[m_coord.column];
|
2012-03-30 15:37:18 +04:00
|
|
|
}
|
|
|
|
|
2012-10-11 02:41:48 +04:00
|
|
|
inline ByteCount BufferIterator::offset() const
|
2012-03-30 15:37:18 +04:00
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer);
|
2013-05-22 20:59:55 +04:00
|
|
|
return m_buffer->offset(m_coord);
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
2012-08-24 01:56:35 +04:00
|
|
|
inline size_t BufferIterator::operator-(const BufferIterator& iterator) const
|
2011-10-18 02:05:06 +04:00
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer == iterator.m_buffer);
|
2013-05-22 20:59:55 +04:00
|
|
|
return (size_t)(int)m_buffer->distance(iterator.m_coord, m_coord);
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
2012-10-11 02:41:48 +04:00
|
|
|
inline BufferIterator BufferIterator::operator+(ByteCount size) const
|
2011-10-18 02:05:06 +04:00
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer);
|
2013-05-22 20:59:55 +04:00
|
|
|
return { *m_buffer, m_buffer->advance(m_coord, size) };
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
2012-10-11 02:41:48 +04:00
|
|
|
inline BufferIterator BufferIterator::operator-(ByteCount size) const
|
2011-10-18 02:05:06 +04:00
|
|
|
{
|
2013-05-22 20:59:55 +04:00
|
|
|
return { *m_buffer, m_buffer->advance(m_coord, -size) };
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
2012-10-11 02:41:48 +04:00
|
|
|
inline BufferIterator& BufferIterator::operator+=(ByteCount size)
|
2011-10-18 02:05:06 +04:00
|
|
|
{
|
2012-03-30 15:37:18 +04:00
|
|
|
return *this = (*this + size);
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
2012-10-11 02:41:48 +04:00
|
|
|
inline BufferIterator& BufferIterator::operator-=(ByteCount size)
|
2011-10-18 02:05:06 +04:00
|
|
|
{
|
2012-03-30 15:37:18 +04:00
|
|
|
return *this = (*this - size);
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline BufferIterator& BufferIterator::operator++()
|
|
|
|
{
|
2012-12-13 17:34:33 +04:00
|
|
|
if (m_coord.column < m_buffer->m_lines[m_coord.line].length() - 1)
|
2012-03-30 16:01:18 +04:00
|
|
|
++m_coord.column;
|
2012-12-13 17:34:33 +04:00
|
|
|
else if (m_coord.line == m_buffer->m_lines.size() - 1)
|
2012-03-30 16:01:18 +04:00
|
|
|
m_coord.column = m_buffer->m_lines.back().length();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++m_coord.line;
|
|
|
|
m_coord.column = 0;
|
|
|
|
}
|
2012-03-31 19:21:14 +04:00
|
|
|
return *this;
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline BufferIterator& BufferIterator::operator--()
|
|
|
|
{
|
2012-03-31 19:21:14 +04:00
|
|
|
if (column() == 0)
|
|
|
|
{
|
|
|
|
if (line() > 0)
|
|
|
|
{
|
|
|
|
--m_coord.line;
|
|
|
|
m_coord.column = m_buffer->m_lines[m_coord.line].length() - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
--m_coord.column;
|
|
|
|
return *this;
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
2012-10-02 16:09:06 +04:00
|
|
|
inline BufferIterator BufferIterator::operator++(int)
|
|
|
|
{
|
|
|
|
BufferIterator save = *this;
|
|
|
|
++*this;
|
|
|
|
return save;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline BufferIterator BufferIterator::operator--(int)
|
|
|
|
{
|
|
|
|
BufferIterator save = *this;
|
|
|
|
--*this;
|
|
|
|
return save;
|
|
|
|
}
|
|
|
|
|
2013-03-15 17:22:42 +04:00
|
|
|
inline BufferIterator& BufferIterator::operator=(const BufferCoord& coord)
|
|
|
|
{
|
2013-05-23 16:29:19 +04:00
|
|
|
kak_assert(m_buffer and m_buffer->is_valid(coord));
|
2013-03-15 17:22:42 +04:00
|
|
|
m_coord = coord;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-10-18 02:05:06 +04:00
|
|
|
inline bool BufferIterator::is_begin() const
|
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer);
|
2012-03-30 15:37:18 +04:00
|
|
|
return m_coord.line == 0 and m_coord.column == 0;
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool BufferIterator::is_end() const
|
|
|
|
{
|
2013-04-09 22:04:11 +04:00
|
|
|
kak_assert(m_buffer);
|
2013-05-22 20:59:55 +04:00
|
|
|
return m_buffer->is_end(m_coord);
|
2011-10-18 02:05:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif // buffer_iterator_inl_h_INCLUDED
|