rename buffer_iterator.inl.hh as buffer.inl.hh and inline some more methods
This commit is contained in:
parent
faabd24e11
commit
3248829f5b
|
@ -157,30 +157,6 @@ BufferCoord Buffer::offset_coord(BufferCoord coord, LineCount offset)
|
|||
return {line, content.byte_count_to(character)};
|
||||
}
|
||||
|
||||
BufferIterator Buffer::begin() const
|
||||
{
|
||||
return BufferIterator(*this, { 0_line, 0 });
|
||||
}
|
||||
|
||||
BufferIterator Buffer::end() const
|
||||
{
|
||||
if (m_lines.empty())
|
||||
return BufferIterator(*this, { 0_line, 0 });
|
||||
return BufferIterator(*this, { line_count()-1, m_lines.back().length() });
|
||||
}
|
||||
|
||||
ByteCount Buffer::byte_count() const
|
||||
{
|
||||
if (m_lines.empty())
|
||||
return 0;
|
||||
return m_lines.back().start + m_lines.back().length();
|
||||
}
|
||||
|
||||
LineCount Buffer::line_count() const
|
||||
{
|
||||
return LineCount(m_lines.size());
|
||||
}
|
||||
|
||||
String Buffer::string(BufferCoord begin, BufferCoord end) const
|
||||
{
|
||||
String res;
|
||||
|
@ -674,20 +650,6 @@ BufferCoord Buffer::advance(BufferCoord coord, ByteCount count) const
|
|||
return { LineCount{ (int)(it - m_lines.begin()) }, off - it->start };
|
||||
}
|
||||
|
||||
BufferCoord Buffer::next(BufferCoord coord) const
|
||||
{
|
||||
if (coord.column < m_lines[coord.line].length() - 1)
|
||||
++coord.column;
|
||||
else if (coord.line == m_lines.size() - 1)
|
||||
coord.column = m_lines.back().length();
|
||||
else
|
||||
{
|
||||
++coord.line;
|
||||
coord.column = 0;
|
||||
}
|
||||
return coord;
|
||||
}
|
||||
|
||||
BufferCoord Buffer::char_next(BufferCoord coord) const
|
||||
{
|
||||
if (coord.column < m_lines[coord.line].length() - 1)
|
||||
|
@ -711,18 +673,6 @@ BufferCoord Buffer::char_next(BufferCoord coord) const
|
|||
return coord;
|
||||
}
|
||||
|
||||
BufferCoord Buffer::prev(BufferCoord coord) const
|
||||
{
|
||||
if (coord.column == 0)
|
||||
{
|
||||
if (coord.line > 0)
|
||||
coord.column = m_lines[--coord.line].length() - 1;
|
||||
}
|
||||
else
|
||||
--coord.column;
|
||||
return coord;
|
||||
}
|
||||
|
||||
BufferCoord Buffer::char_prev(BufferCoord coord) const
|
||||
{
|
||||
kak_assert(is_valid(coord));
|
||||
|
@ -741,36 +691,6 @@ BufferCoord Buffer::char_prev(BufferCoord coord) const
|
|||
return coord;
|
||||
}
|
||||
|
||||
ByteCount Buffer::distance(BufferCoord begin, BufferCoord end) const
|
||||
{
|
||||
return offset(end) - offset(begin);
|
||||
}
|
||||
|
||||
ByteCount Buffer::offset(BufferCoord c) const
|
||||
{
|
||||
if (c.line == line_count())
|
||||
return m_lines.back().start + m_lines.back().length();
|
||||
return m_lines[c.line].start + c.column;
|
||||
}
|
||||
|
||||
bool Buffer::is_valid(BufferCoord c) const
|
||||
{
|
||||
return (c.line < line_count() and c.column < m_lines[c.line].length()) or
|
||||
(c.line == line_count() - 1 and c.column == m_lines.back().length()) or
|
||||
(c.line == line_count() and c.column == 0);
|
||||
}
|
||||
|
||||
bool Buffer::is_end(BufferCoord c) const
|
||||
{
|
||||
return c >= BufferCoord{line_count() - 1, m_lines.back().length()};
|
||||
}
|
||||
|
||||
char Buffer::byte_at(BufferCoord c) const
|
||||
{
|
||||
kak_assert(c.line < line_count() and c.column < m_lines[c.line].length());
|
||||
return m_lines[c.line].content[c.column];
|
||||
}
|
||||
|
||||
time_t Buffer::fs_timestamp() const
|
||||
{
|
||||
kak_assert(m_flags & Flags::File);
|
||||
|
|
|
@ -287,6 +287,6 @@ public:
|
|||
|
||||
}
|
||||
|
||||
#include "buffer_iterator.inl.hh"
|
||||
#include "buffer.inl.hh"
|
||||
|
||||
#endif // buffer_hh_INCLUDED
|
||||
|
|
|
@ -1,11 +1,91 @@
|
|||
#ifndef buffer_iterator_inl_h_INCLUDED
|
||||
#define buffer_iterator_inl_h_INCLUDED
|
||||
#ifndef buffer_inl_h_INCLUDED
|
||||
#define buffer_inl_h_INCLUDED
|
||||
|
||||
#include "assert.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
inline char Buffer::byte_at(BufferCoord c) const
|
||||
{
|
||||
kak_assert(c.line < line_count() and c.column < m_lines[c.line].length());
|
||||
return m_lines[c.line].content[c.column];
|
||||
}
|
||||
|
||||
inline BufferCoord Buffer::next(BufferCoord coord) const
|
||||
{
|
||||
if (coord.column < m_lines[coord.line].length() - 1)
|
||||
++coord.column;
|
||||
else if (coord.line == m_lines.size() - 1)
|
||||
coord.column = m_lines.back().length();
|
||||
else
|
||||
{
|
||||
++coord.line;
|
||||
coord.column = 0;
|
||||
}
|
||||
return coord;
|
||||
}
|
||||
|
||||
inline BufferCoord Buffer::prev(BufferCoord coord) const
|
||||
{
|
||||
if (coord.column == 0)
|
||||
{
|
||||
if (coord.line > 0)
|
||||
coord.column = m_lines[--coord.line].length() - 1;
|
||||
}
|
||||
else
|
||||
--coord.column;
|
||||
return coord;
|
||||
}
|
||||
|
||||
inline ByteCount Buffer::distance(BufferCoord begin, BufferCoord end) const
|
||||
{
|
||||
return offset(end) - offset(begin);
|
||||
}
|
||||
|
||||
inline ByteCount Buffer::offset(BufferCoord c) const
|
||||
{
|
||||
if (c.line == line_count())
|
||||
return m_lines.back().start + m_lines.back().length();
|
||||
return m_lines[c.line].start + c.column;
|
||||
}
|
||||
|
||||
inline bool Buffer::is_valid(BufferCoord c) const
|
||||
{
|
||||
return (c.line < line_count() and c.column < m_lines[c.line].length()) or
|
||||
(c.line == line_count() - 1 and c.column == m_lines.back().length()) or
|
||||
(c.line == line_count() and c.column == 0);
|
||||
}
|
||||
|
||||
inline bool Buffer::is_end(BufferCoord c) const
|
||||
{
|
||||
return c >= BufferCoord{line_count() - 1, m_lines.back().length()};
|
||||
}
|
||||
|
||||
inline BufferIterator Buffer::begin() const
|
||||
{
|
||||
return BufferIterator(*this, { 0_line, 0 });
|
||||
}
|
||||
|
||||
inline BufferIterator Buffer::end() const
|
||||
{
|
||||
if (m_lines.empty())
|
||||
return BufferIterator(*this, { 0_line, 0 });
|
||||
return BufferIterator(*this, { line_count()-1, m_lines.back().length() });
|
||||
}
|
||||
|
||||
inline ByteCount Buffer::byte_count() const
|
||||
{
|
||||
if (m_lines.empty())
|
||||
return 0;
|
||||
return m_lines.back().start + m_lines.back().length();
|
||||
}
|
||||
|
||||
inline LineCount Buffer::line_count() const
|
||||
{
|
||||
return LineCount(m_lines.size());
|
||||
}
|
||||
|
||||
inline BufferIterator::BufferIterator(const Buffer& buffer, BufferCoord coord)
|
||||
: m_buffer(&buffer), m_coord(coord)
|
||||
{
|
||||
|
@ -110,4 +190,4 @@ inline BufferIterator BufferIterator::operator--(int)
|
|||
}
|
||||
|
||||
}
|
||||
#endif // buffer_iterator_inl_h_INCLUDED
|
||||
#endif // buffer_inl_h_INCLUDED
|
Loading…
Reference in New Issue
Block a user