diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-03-06 00:07:06 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-03-06 15:12:36 +0000 |
| commit | fb2fb3811fb28ffa1dfa69f471260ea2e47996f7 (patch) | |
| tree | 861a7ba4439c0a3756e90efbc70641d6aaedac27 /src/selectors.hh | |
| parent | 72b6340b35af1b85f9bfc25e6092101654eba84b (diff) | |
Tweak useage of skip_while and move the functions in utils.hh
Diffstat (limited to 'src/selectors.hh')
| -rw-r--r-- | src/selectors.hh | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/src/selectors.hh b/src/selectors.hh index 12ec7491..fd896068 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -24,20 +24,6 @@ inline Selection target_eol(Selection sel) return sel; } -template<typename Iterator, typename EndIterator, typename T> -void skip_while(Iterator& it, const EndIterator& end, T condition) -{ - while (it != end and condition(*it)) - ++it; -} - -template<typename Iterator, typename BeginIterator, typename T> -void skip_while_reverse(Iterator& it, const BeginIterator& begin, T condition) -{ - while (it != begin and condition(*it)) - --it; -} - using Utf8Iterator = utf8::iterator<BufferIterator, utf8::InvalidPolicy::Pass>; inline Selection utf8_range(const BufferIterator& first, const BufferIterator& last) @@ -59,8 +45,8 @@ Selection select_to_next_word(const Buffer& buffer, const Selection& selection) if (categorize<word_type>(*begin) != categorize<word_type>(*(begin+1))) ++begin; - skip_while(begin, buffer.end(), [](Codepoint c){ return is_eol(c); }); - if (begin == buffer.end()) + if (not skip_while(begin, buffer.end(), + [](Codepoint c) { return is_eol(c); })) return selection; Utf8Iterator end = begin+1; @@ -83,8 +69,8 @@ Selection select_to_next_word_end(const Buffer& buffer, const Selection& selecti if (categorize<word_type>(*begin) != categorize<word_type>(*(begin+1))) ++begin; - skip_while(begin, buffer.end(), [](Codepoint c){ return is_eol(c); }); - if (begin == buffer.end()) + if (not skip_while(begin, buffer.end(), + [](Codepoint c) { return is_eol(c); })) return selection; Utf8Iterator end = begin; skip_while(end, buffer.end(), is_horizontal_blank); @@ -112,15 +98,10 @@ Selection select_to_previous_word(const Buffer& buffer, const Selection& selecti bool with_end = false; if (word_type == Word and is_punctuation(*end)) - { - skip_while_reverse(end, buffer.begin(), is_punctuation); - with_end = is_punctuation(*end); - } + with_end = skip_while_reverse(end, buffer.begin(), is_punctuation); + else if (is_word<word_type>(*end)) - { - skip_while_reverse(end, buffer.begin(), is_word<word_type>); - with_end = is_word<word_type>(*end); - } + with_end = skip_while_reverse(end, buffer.begin(), is_word<word_type>); return utf8_range(begin, with_end ? end : end+1); } |
