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

View File

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