Small refactoring in selectors.cc

This commit is contained in:
Maxime Coste 2015-07-01 23:54:17 +01:00
parent 28ebe776c0
commit 2660793a31

View File

@ -226,13 +226,12 @@ Selection select_number(const Buffer& buffer, const Selection& selection, Object
: Selection{last.coord(), first.coord()}; : Selection{last.coord(), first.coord()};
} }
static bool is_end_of_sentence(char c)
{
return c == '.' or c == ';' or c == '!' or c == '?';
}
Selection select_sentence(const Buffer& buffer, const Selection& selection, ObjectFlags flags) Selection select_sentence(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
{ {
auto is_end_of_sentence = [](char c) {
return c == '.' or c == ';' or c == '!' or c == '?';
};
BufferIterator first = buffer.iterator_at(selection.cursor()); BufferIterator first = buffer.iterator_at(selection.cursor());
if (not (flags & ObjectFlags::ToEnd)) if (not (flags & ObjectFlags::ToEnd))
@ -372,8 +371,9 @@ Selection select_whitespaces(const Buffer& buffer, const Selection& selection, O
: utf8_range(last, first); : utf8_range(last, first);
} }
static CharCount get_indent(StringView str, int tabstop) Selection select_indent(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
{ {
auto get_indent = [](StringView str, int tabstop) {
CharCount indent = 0; CharCount indent = 0;
for (auto& c : str) for (auto& c : str)
{ {
@ -385,18 +385,15 @@ static CharCount get_indent(StringView str, int tabstop)
break; break;
} }
return indent; return indent;
} };
static bool is_only_whitespaces(StringView str) auto is_only_whitespaces = [](StringView str) {
{
auto it = str.begin(); auto it = str.begin();
skip_while(it, str.end(), skip_while(it, str.end(),
[](char c){ return c == ' ' or c == '\t' or c == '\n'; }); [](char c){ return c == ' ' or c == '\t' or c == '\n'; });
return it == str.end(); return it == str.end();
} };
Selection select_indent(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
{
int tabstop = buffer.options()["tabstop"].get<int>(); int tabstop = buffer.options()["tabstop"].get<int>();
LineCount line = selection.cursor().line; LineCount line = selection.cursor().line;
auto indent = get_indent(buffer[line], tabstop); auto indent = get_indent(buffer[line], tabstop);