remove avoid_eol parameter from Buffer::{iterator_at,clamp}

This commit is contained in:
Maxime Coste 2013-05-30 14:17:19 +02:00
parent 07c8379313
commit 28e127a48a
2 changed files with 13 additions and 22 deletions

View File

@ -86,10 +86,9 @@ bool Buffer::set_name(String name)
return false;
}
BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column,
bool avoid_eol) const
BufferIterator Buffer::iterator_at(const BufferCoord& coord) const
{
return BufferIterator(*this, clamp(line_and_column, avoid_eol));
return BufferIterator(*this, clamp(coord));
}
ByteCount Buffer::line_length(LineCount line) const
@ -98,17 +97,15 @@ ByteCount Buffer::line_length(LineCount line) const
return m_lines[line].length();
}
BufferCoord Buffer::clamp(const BufferCoord& line_and_column,
bool avoid_eol) const
BufferCoord Buffer::clamp(BufferCoord coord) const
{
if (m_lines.empty())
return BufferCoord();
return BufferCoord{};
BufferCoord result(line_and_column.line, line_and_column.column);
result.line = Kakoune::clamp(result.line, 0_line, line_count() - 1);
ByteCount max_col = std::max(0_byte, line_length(result.line) - (avoid_eol ? 2 : 1));
result.column = Kakoune::clamp(result.column, 0_byte, max_col);
return result;
coord.line = Kakoune::clamp(coord.line, 0_line, line_count() - 1);
ByteCount max_col = std::max(0_byte, line_length(coord.line) - 1);
coord.column = Kakoune::clamp(coord.column, 0_byte, max_col);
return coord;
}
BufferIterator Buffer::iterator_at_line_begin(LineCount line) const

View File

@ -119,12 +119,10 @@ public:
bool undo();
bool redo();
String string(const BufferCoord& begin,
const BufferCoord& end) const;
String string(const BufferCoord& begin, const BufferCoord& end) const;
char at(const BufferCoord& c) const;
ByteCount offset(const BufferCoord& c) const;
ByteCount distance(const BufferCoord& begin,
const BufferCoord& end) const;
ByteCount distance(const BufferCoord& begin, const BufferCoord& end) const;
BufferCoord advance(BufferCoord coord, ByteCount count) const;
BufferCoord next(BufferCoord coord) const;
BufferCoord prev(BufferCoord coord) const;
@ -139,15 +137,11 @@ public:
const String& line_content(LineCount line) const
{ return m_lines[line].content; }
// returns an iterator at given coordinates. line_and_column is
// clamped according to avoid_eol.
BufferIterator iterator_at(const BufferCoord& line_and_column,
bool avoid_eol = false) const;
// returns an iterator at given coordinates. clamp line_and_column
BufferIterator iterator_at(const BufferCoord& coord) const;
// returns nearest valid coordinates from given ones
// if avoid_eol, clamp to character before eol if line is not empty
BufferCoord clamp(const BufferCoord& line_and_column,
bool avoid_eol = false) const;
BufferCoord clamp(BufferCoord coord) const;
// returns an iterator pointing to the first character of the line
// iterator is on