Remove is_blank, which is identical to is_horizontal_blank

This commit is contained in:
Maxime Coste 2015-04-15 00:34:00 +01:00
parent 63bbb6e3df
commit bf02838816
5 changed files with 18 additions and 23 deletions

View File

@ -17,10 +17,10 @@ Completions shell_complete(const Context& context, CompletionFlags flags,
{ {
command = (pos == 0 or prefix[pos-1] == ';' or prefix[pos-1] == '|' or command = (pos == 0 or prefix[pos-1] == ';' or prefix[pos-1] == '|' or
(pos > 1 and prefix[pos-1] == '&' and prefix[pos-2] == '&')); (pos > 1 and prefix[pos-1] == '&' and prefix[pos-2] == '&'));
while (pos != len and is_blank(prefix[pos])) while (pos != len and is_horizontal_blank(prefix[pos]))
++pos; ++pos;
word_start = pos; word_start = pos;
while (pos != len and not is_blank(prefix[pos])) while (pos != len and not is_horizontal_blank(prefix[pos]))
++pos; ++pos;
word_end = pos; word_end = pos;
} }

View File

@ -266,7 +266,7 @@ void to_next_word_begin(CharCount& pos, StringView line)
while (pos != len and is_word<word_type>(line[pos])) while (pos != len and is_word<word_type>(line[pos]))
++pos; ++pos;
} }
while (pos != len and is_blank(line[pos])) while (pos != len and is_horizontal_blank(line[pos]))
++pos; ++pos;
} }
@ -278,7 +278,7 @@ void to_next_word_end(CharCount& pos, StringView line)
return; return;
++pos; ++pos;
while (pos != len and is_blank(line[pos])) while (pos != len and is_horizontal_blank(line[pos]))
++pos; ++pos;
if (word_type == Word and is_punctuation(line[pos])) if (word_type == Word and is_punctuation(line[pos]))
@ -301,7 +301,7 @@ void to_prev_word_begin(CharCount& pos, StringView line)
return; return;
--pos; --pos;
while (pos != 0_char and is_blank(line[pos])) while (pos != 0_char and is_horizontal_blank(line[pos]))
--pos; --pos;
if (word_type == Word and is_punctuation(line[pos])) if (word_type == Word and is_punctuation(line[pos]))

View File

@ -259,7 +259,7 @@ Selection select_sentence(const Buffer& buffer, const Selection& selection, Obje
{ {
BufferIterator prev_non_blank = first-1; BufferIterator prev_non_blank = first-1;
skip_while_reverse(prev_non_blank, buffer.begin(), skip_while_reverse(prev_non_blank, buffer.begin(),
[](char c) { return is_blank(c) or is_eol(c); }); [](char c) { return is_horizontal_blank(c) or is_eol(c); });
if (is_end_of_sentence(*prev_non_blank)) if (is_end_of_sentence(*prev_non_blank))
first = prev_non_blank; first = prev_non_blank;
} }
@ -273,7 +273,7 @@ Selection select_sentence(const Buffer& buffer, const Selection& selection, Obje
{ {
char cur = *first; char cur = *first;
char prev = *(first-1); char prev = *(first-1);
if (not is_blank(cur)) if (not is_horizontal_blank(cur))
saw_non_blank = true; saw_non_blank = true;
if (is_eol(prev) and is_eol(cur)) if (is_eol(prev) and is_eol(cur))
{ {
@ -289,7 +289,7 @@ Selection select_sentence(const Buffer& buffer, const Selection& selection, Obje
} }
--first; --first;
} }
skip_while(first, buffer.end(), is_blank); skip_while(first, buffer.end(), is_horizontal_blank);
} }
if (flags & ObjectFlags::ToEnd) if (flags & ObjectFlags::ToEnd)
{ {
@ -304,7 +304,7 @@ Selection select_sentence(const Buffer& buffer, const Selection& selection, Obje
if (not (flags & ObjectFlags::Inner) and last != buffer.end()) if (not (flags & ObjectFlags::Inner) and last != buffer.end())
{ {
++last; ++last;
skip_while(last, buffer.end(), is_blank); skip_while(last, buffer.end(), is_horizontal_blank);
--last; --last;
} }
} }

View File

@ -58,7 +58,7 @@ Selection select_to_next_word(const Buffer& buffer, const Selection& selection)
else if (is_word<word_type>(*begin)) else if (is_word<word_type>(*begin))
skip_while(end, buffer.end(), is_word<word_type>); skip_while(end, buffer.end(), is_word<word_type>);
skip_while(end, buffer.end(), is_blank); skip_while(end, buffer.end(), is_horizontal_blank);
return utf8_range(begin, end-1); return utf8_range(begin, end-1);
} }
@ -76,7 +76,7 @@ Selection select_to_next_word_end(const Buffer& buffer, const Selection& selecti
if (begin == buffer.end()) if (begin == buffer.end())
return selection; return selection;
Utf8Iterator end = begin; Utf8Iterator end = begin;
skip_while(end, buffer.end(), is_blank); skip_while(end, buffer.end(), is_horizontal_blank);
if (word_type == Word and is_punctuation(*end)) if (word_type == Word and is_punctuation(*end))
skip_while(end, buffer.end(), is_punctuation); skip_while(end, buffer.end(), is_punctuation);
@ -97,7 +97,7 @@ Selection select_to_previous_word(const Buffer& buffer, const Selection& selecti
skip_while_reverse(begin, buffer.begin(), is_eol); skip_while_reverse(begin, buffer.begin(), is_eol);
Utf8Iterator end = begin; Utf8Iterator end = begin;
skip_while_reverse(end, buffer.begin(), is_blank); skip_while_reverse(end, buffer.begin(), is_horizontal_blank);
bool with_end = false; bool with_end = false;
if (word_type == Word and is_punctuation(*end)) if (word_type == Word and is_punctuation(*end))
@ -153,7 +153,7 @@ Selection select_word(const Buffer& buffer,
{ {
skip_while(last, buffer.end(), is_word<word_type>); skip_while(last, buffer.end(), is_word<word_type>);
if (not (flags & ObjectFlags::Inner)) if (not (flags & ObjectFlags::Inner))
skip_while(last, buffer.end(), is_blank); skip_while(last, buffer.end(), is_horizontal_blank);
--last; --last;
} }
} }
@ -161,7 +161,7 @@ Selection select_word(const Buffer& buffer,
{ {
if (flags & ObjectFlags::ToBegin) if (flags & ObjectFlags::ToBegin)
{ {
skip_while_reverse(first, buffer.begin(), is_blank); skip_while_reverse(first, buffer.begin(), is_horizontal_blank);
if (not is_word<word_type>(*first)) if (not is_word<word_type>(*first))
return selection; return selection;
skip_while_reverse(first, buffer.begin(), is_word<word_type>); skip_while_reverse(first, buffer.begin(), is_word<word_type>);
@ -170,7 +170,7 @@ Selection select_word(const Buffer& buffer,
} }
if (flags & ObjectFlags::ToEnd) if (flags & ObjectFlags::ToEnd)
{ {
skip_while(last, buffer.end(), is_blank); skip_while(last, buffer.end(), is_horizontal_blank);
--last; --last;
} }
} }

View File

@ -15,11 +15,6 @@ inline bool is_eol(Codepoint c)
return c == '\n'; return c == '\n';
} }
inline bool is_blank(Codepoint c)
{
return c == ' ' or c == '\t';
}
inline bool is_horizontal_blank(Codepoint c) inline bool is_horizontal_blank(Codepoint c)
{ {
return c == ' ' or c == '\t'; return c == ' ' or c == '\t';
@ -36,12 +31,12 @@ inline bool is_word(Codepoint c)
template<> template<>
inline bool is_word<WORD>(Codepoint c) inline bool is_word<WORD>(Codepoint c)
{ {
return not is_blank(c) and not is_eol(c); return not is_horizontal_blank(c) and not is_eol(c);
} }
inline bool is_punctuation(Codepoint c) inline bool is_punctuation(Codepoint c)
{ {
return not (is_word(c) or is_blank(c) or is_eol(c)); return not (is_word(c) or is_horizontal_blank(c) or is_eol(c));
} }
enum class CharCategories enum class CharCategories
@ -59,7 +54,7 @@ inline CharCategories categorize(Codepoint c)
return CharCategories::Word; return CharCategories::Word;
if (is_eol(c)) if (is_eol(c))
return CharCategories::EndOfLine; return CharCategories::EndOfLine;
if (is_blank(c)) if (is_horizontal_blank(c))
return CharCategories::Blank; return CharCategories::Blank;
return word_type == WORD ? CharCategories::Word return word_type == WORD ? CharCategories::Word
: CharCategories::Punctuation; : CharCategories::Punctuation;