Remove Buffer::iterator_at_line_{begin,end}, use iterator_at(line{,+1})

This commit is contained in:
Maxime Coste 2013-06-03 19:10:28 +02:00
parent 503f0cce25
commit c4f9253634
6 changed files with 11 additions and 49 deletions

View File

@ -108,30 +108,6 @@ BufferCoord Buffer::clamp(BufferCoord coord) const
return coord; return coord;
} }
BufferIterator Buffer::iterator_at_line_begin(LineCount line) const
{
line = Kakoune::clamp(line, 0_line, line_count()-1);
kak_assert(line_length(line) > 0);
return BufferIterator(*this, { line, 0 });
}
BufferIterator Buffer::iterator_at_line_begin(const BufferIterator& iterator) const
{
return iterator_at_line_begin(iterator.line());
}
BufferIterator Buffer::iterator_at_line_end(LineCount line) const
{
line = Kakoune::clamp(line, 0_line, line_count()-1);
kak_assert(line_length(line) > 0);
return ++BufferIterator(*this, { line, line_length(line) - 1 });
}
BufferIterator Buffer::iterator_at_line_end(const BufferIterator& iterator) const
{
return iterator_at_line_end(iterator.line());
}
BufferIterator Buffer::begin() const BufferIterator Buffer::begin() const
{ {
return BufferIterator(*this, { 0_line, 0 }); return BufferIterator(*this, { 0_line, 0 });
@ -729,8 +705,7 @@ bool Buffer::is_valid(const BufferCoord& c) const
bool Buffer::is_end(const BufferCoord& c) const bool Buffer::is_end(const BufferCoord& c) const
{ {
return (c.line == line_count() and c.column == 0) or return c >= BufferCoord{line_count() - 1, m_lines.back().length()};
(c.line == line_count() - 1 and c.column == m_lines.back().length());
} }
char Buffer::byte_at(const BufferCoord& c) const char Buffer::byte_at(const BufferCoord& c) const

View File

@ -151,19 +151,6 @@ public:
// returns nearest valid coordinates from given ones // returns nearest valid coordinates from given ones
BufferCoord clamp(BufferCoord coord) const; BufferCoord clamp(BufferCoord coord) const;
// returns an iterator pointing to the first character of the line
// iterator is on
BufferIterator iterator_at_line_begin(const BufferIterator& iterator) const;
// the same but taking a line number instead of an iterator
BufferIterator iterator_at_line_begin(LineCount line) const;
// returns an iterator pointing to the character after the last of the
// line iterator is on (which is the first of the next line if iterator is
// not on the last one)
BufferIterator iterator_at_line_end(const BufferIterator& iterator) const;
// the same but taking a line number instead of an iterator
BufferIterator iterator_at_line_end(LineCount line) const;
const String& name() const { return m_name; } const String& name() const { return m_name; }
String display_name() const; String display_name() const;

View File

@ -42,7 +42,7 @@ void expand_tabulations(Buffer& buffer, Selection& selection, String& content)
{ {
int column = 0; int column = 0;
const auto position = buffer.iterator_at(selection.last()); const auto position = buffer.iterator_at(selection.last());
for (auto it = buffer.iterator_at_line_begin(position); for (auto it = buffer.iterator_at(position.line());
it != position; ++it) it != position; ++it)
{ {
kak_assert(*it != '\n'); kak_assert(*it != '\n');
@ -67,7 +67,7 @@ struct RegexFilter
void operator() (Buffer& buffer, Selection& selection, String& content) void operator() (Buffer& buffer, Selection& selection, String& content)
{ {
const auto position = buffer.iterator_at(selection.last()); const auto position = buffer.iterator_at(selection.last());
auto line_begin = buffer.iterator_at_line_begin(position); auto line_begin = buffer.iterator_at(position.line());
boost::match_results<BufferIterator> results; boost::match_results<BufferIterator> results;
if (boost::regex_match(content.c_str(), m_insert_match) and if (boost::regex_match(content.c_str(), m_insert_match) and
boost::regex_match(line_begin, position, results, m_line_match)) boost::regex_match(line_begin, position, results, m_line_match))

View File

@ -235,7 +235,7 @@ void expand_tabulations(const Window& window, DisplayBuffer& display_buffer)
atom_it = line.split(atom_it, (it+1).coord()); atom_it = line.split(atom_it, (it+1).coord());
int column = 0; int column = 0;
for (auto line_it = buffer.iterator_at_line_begin(it); for (auto line_it = buffer.iterator_at(it.line());
line_it != it; ++line_it) line_it != it; ++line_it)
{ {
kak_assert(*line_it != '\n'); kak_assert(*line_it != '\n');

View File

@ -92,7 +92,7 @@ void goto_commands(Context& context)
{ {
context.push_jump(); context.push_jump();
const Buffer& buf = editor.buffer(); const Buffer& buf = editor.buffer();
editor.select(buf.iterator_at_line_begin(buf.line_count() - 1), mode); editor.select(buf.iterator_at(buf.line_count() - 1), mode);
break; break;
} }
case 'e': case 'e':
@ -103,7 +103,7 @@ void goto_commands(Context& context)
if (context.has_window()) if (context.has_window())
{ {
auto line = context.window().position().line; auto line = context.window().position().line;
editor.select(editor.buffer().iterator_at_line_begin(line), mode); editor.select(editor.buffer().iterator_at(line), mode);
} }
break; break;
case 'b': case 'b':
@ -111,7 +111,7 @@ void goto_commands(Context& context)
{ {
auto& window = context.window(); auto& window = context.window();
auto line = window.position().line + window.dimensions().line - 1; auto line = window.position().line + window.dimensions().line - 1;
editor.select(editor.buffer().iterator_at_line_begin(line), mode); editor.select(editor.buffer().iterator_at(line), mode);
} }
break; break;
case 'c': case 'c':
@ -119,7 +119,7 @@ void goto_commands(Context& context)
{ {
auto& window = context.window(); auto& window = context.window();
auto line = window.position().line + window.dimensions().line / 2; auto line = window.position().line + window.dimensions().line / 2;
editor.select(editor.buffer().iterator_at_line_begin(line), mode); editor.select(editor.buffer().iterator_at(line), mode);
} }
break; break;
case 'a': case 'a':
@ -608,8 +608,8 @@ void scroll(Context& context)
position.line += (window.dimensions().line - 2); position.line += (window.dimensions().line - 2);
cursor_line = position.line + window.dimensions().line - 1; cursor_line = position.line + window.dimensions().line - 1;
} }
auto cursor_pos = utf8::advance(buffer.iterator_at_line_begin(position.line), auto cursor_pos = utf8::advance(buffer.iterator_at(position.line),
buffer.iterator_at_line_end(position.line), buffer.iterator_at(position.line+1),
position.column); position.column);
window.select(cursor_pos); window.select(cursor_pos);
window.set_position(position); window.set_position(position);

View File

@ -68,7 +68,7 @@ void test_editor()
} }
editor.undo(); editor.undo();
Selection sel{ buffer.iterator_at_line_begin(2_line), buffer.end()-1 }; Selection sel{ buffer.iterator_at(2_line), buffer.end()-1 };
editor.select(sel, SelectMode::Replace); editor.select(sel, SelectMode::Replace);
editor.insert("",InsertMode::Replace); editor.insert("",InsertMode::Replace);
kak_assert(not buffer.is_end(editor.main_selection().first())); kak_assert(not buffer.is_end(editor.main_selection().first()));