From 47a82b9855fe440afb3b533c899b9cbe38a898c2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 20 Nov 2016 11:15:15 +0000 Subject: [PATCH] Make ArrayView::subrange size arguement optional --- src/array_view.hh | 5 +++-- src/command_manager.cc | 2 +- src/highlighters.cc | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/array_view.hh b/src/array_view.hh index 1366805a..0c4c9b51 100644 --- a/src/array_view.hh +++ b/src/array_view.hh @@ -60,9 +60,10 @@ public: constexpr bool empty() const { return m_size == 0; } - constexpr ArrayView subrange(size_t first, size_t count) const + constexpr ArrayView subrange(size_t first, size_t count = -1) const { - return ArrayView(m_pointer + first, count); + return ArrayView(m_pointer + std::min(first, m_size), + std::min(count, m_size - std::min(first, m_size))); } private: diff --git a/src/command_manager.cc b/src/command_manager.cc index 1fbdd804..9a484f2a 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -662,7 +662,7 @@ Completions CommandManager::complete(const Context& context, auto command_it = find_command(context, command_name); if (command_it != m_commands.end() and command_it->second.completer) return command_it->second.completer( - context, flags, params.subrange(1, params.size()-1), + context, flags, params.subrange(1), token_to_complete-1, pos_in_token); } return Completions{}; diff --git a/src/highlighters.cc b/src/highlighters.cc index 94e938e7..3cf93b02 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -250,7 +250,7 @@ public: throw runtime_error("wrong parameter count"); FacesSpec faces; - for (auto& spec : params.subrange(1, params.size()-1)) + for (auto& spec : params.subrange(1)) { auto colon = find(spec, ':'); if (colon == spec.end()) @@ -440,7 +440,7 @@ HighlighterAndId create_dynamic_regex_highlighter(HighlighterParameters params) throw runtime_error("Wrong parameter count"); FacesSpec faces; - for (auto& spec : params.subrange(1, params.size()-1)) + for (auto& spec : params.subrange(1)) { auto colon = find(spec, ':'); if (colon == spec.end())