diff options
| author | Maxime Coste <mawww@kakoune.org> | 2019-07-21 12:14:25 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2019-07-21 12:14:25 +1000 |
| commit | b18ca1288259876812f4ba1904ee2ea576f6fbb5 (patch) | |
| tree | db5916b27466677411430b15e262cd3f2bcac579 /src | |
| parent | c54e0ec8732ba717d1dc55d8b3c7119f2489ea10 (diff) | |
More functional style for '*' code
Diffstat (limited to 'src')
| -rw-r--r-- | src/normal.cc | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/normal.cc b/src/normal.cc index 209c7808..0dd56af7 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -939,20 +939,14 @@ template<bool smart> void use_selection_as_search_pattern(Context& context, NormalParams params) { const auto& buffer = context.buffer(); - String pattern; - - for (auto& sel : context.selections()) - { + auto patterns = context.selections() | transform([&](auto&& sel) { const auto beg = sel.min(), end = buffer.char_next(sel.max()); - const String sel_pattern = format("{}{}{}", - smart and is_bow(buffer, beg) ? "\\b" : "", - escape(buffer.string(beg, end), "^$\\.*+?()[]{}|", '\\'), - smart and is_eow(buffer, end) ? "\\b" : ""); - - if (not pattern.empty()) - pattern += '|'; - pattern += sel_pattern; - } + return format("{}{}{}", + smart and is_bow(buffer, beg) ? "\\b" : "", + escape(buffer.string(beg, end), "^$\\.*+?()[]{}|", '\\'), + smart and is_eow(buffer, end) ? "\\b" : ""); + }); + String pattern = join(patterns, '|', false); const char reg = to_lower(params.reg ? params.reg : '/'); |
