diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-02-17 23:40:14 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-02-17 23:40:14 +0000 |
| commit | 47df1374fe4a8ed5575ae607c654bbf68988ebb4 (patch) | |
| tree | 237542cc432f31bd07074246af2d83aae4cdf813 /src/normal.cc | |
| parent | 85a8a0c26d68c1cba203810aaa5cd42e635112cb (diff) | |
Refactor use selection as search pattern implementation
Diffstat (limited to 'src/normal.cc')
| -rw-r--r-- | src/normal.cc | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/normal.cc b/src/normal.cc index 78877f91..0702ca62 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -670,22 +670,13 @@ void use_selection_as_search_pattern(Context& context, NormalParams params) Vector<String> patterns; auto& sels = context.selections(); const auto& buffer = context.buffer(); - using Utf8It = utf8::iterator<BufferIterator, utf8::InvalidPolicy::Pass>; for (auto& sel : sels) { - Utf8It begin{buffer.iterator_at(sel.min()), buffer}; - Utf8It end{buffer.iterator_at(sel.max()), buffer}; - ++end; - - auto content = "\\Q" + buffer.string(begin.base().coord(), end.base().coord()) + "\\E"; - if (smart) - { - if (is_word(*begin) and (begin == buffer.begin() or not is_word(*(begin-1)))) - content = "\\b" + content; - if (is_word(*(end-1)) and (end == buffer.end() or not is_word(*end))) - content = content + "\\b"; - } - patterns.push_back(std::move(content)); + const auto beg = sel.min(), end = buffer.char_next(sel.max()); + patterns.push_back(format("{}\\Q{}\\E{}", + smart and is_bow(buffer, beg) ? "\\b" : "", + buffer.string(beg, end), + smart and is_eow(buffer, end) ? "\\b" : "")); } const char reg = to_lower(params.reg ? params.reg : '/'); |
