minor code cleanups in filters.cc

This commit is contained in:
Maxime Coste 2013-05-27 19:20:59 +02:00
parent 557acc5068
commit dbb1c57ec9

View File

@ -10,8 +10,8 @@ void preserve_indent(Buffer& buffer, Selection& selection, String& content)
{ {
if (content == "\n") if (content == "\n")
{ {
BufferIterator line_begin = buffer.iterator_at_line_begin(selection.last() - 1); BufferCoord line_begin{selection.last().line(), 0};
BufferIterator first_non_white = line_begin; auto first_non_white = buffer.iterator_at(line_begin);
while ((*first_non_white == '\t' or *first_non_white == ' ') and while ((*first_non_white == '\t' or *first_non_white == ' ') and
not first_non_white.is_end()) not first_non_white.is_end())
++first_non_white; ++first_non_white;
@ -22,10 +22,10 @@ void preserve_indent(Buffer& buffer, Selection& selection, String& content)
void cleanup_whitespaces(Buffer& buffer, Selection& selection, String& content) void cleanup_whitespaces(Buffer& buffer, Selection& selection, String& content)
{ {
const BufferIterator& position = selection.last(); const auto position = buffer.iterator_at(selection.last());
if (content[0] == '\n' and not position.is_begin()) if (content[0] == '\n' and not position.is_begin())
{ {
BufferIterator whitespace_start = position-1; auto whitespace_start = position-1;
while ((*whitespace_start == ' ' or *whitespace_start == '\t') and while ((*whitespace_start == ' ' or *whitespace_start == '\t') and
not whitespace_start .is_begin()) not whitespace_start .is_begin())
--whitespace_start; --whitespace_start;
@ -41,21 +41,19 @@ void expand_tabulations(Buffer& buffer, Selection& selection, String& content)
if (content == "\t") if (content == "\t")
{ {
int column = 0; int column = 0;
const BufferIterator& position = selection.last(); const auto position = buffer.iterator_at(selection.last());
for (auto line_it = buffer.iterator_at_line_begin(position); for (auto it = buffer.iterator_at_line_begin(position);
line_it != position; ++line_it) it != position; ++it)
{ {
kak_assert(*line_it != '\n'); kak_assert(*it != '\n');
if (*line_it == '\t') if (*it == '\t')
column += tabstop - (column % tabstop); column += tabstop - (column % tabstop);
else else
++column; ++column;
} }
int count = tabstop - (column % tabstop); CharCount count = tabstop - (column % tabstop);
content = String(); content = String(' ', count);
for (int i = 0; i < count; ++i)
content += ' ';
} }
} }
@ -68,7 +66,7 @@ struct RegexFilter
void operator() (Buffer& buffer, Selection& selection, String& content) void operator() (Buffer& buffer, Selection& selection, String& content)
{ {
const auto& position = 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_line_begin(position);
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