From 7316afd17b37f96dbaf9e19d96509eca5d8e407a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 16 Jan 2017 18:49:27 +0000 Subject: [PATCH] Use ints instead of unsigned for capture count --- src/normal.cc | 6 +++--- src/selectors.cc | 10 +++++----- src/selectors.hh | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index c57fbc48..af72e000 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -759,8 +759,8 @@ void use_selection_as_search_pattern(Context& context, NormalParams params) void select_regex(Context& context, NormalParams params) { const char reg = to_lower(params.reg ? params.reg : '/'); - const unsigned capture = (unsigned)params.count; - auto prompt = capture ? format("select (capture {}):", (int)capture) : "select:"_str; + const int capture = params.count; + auto prompt = capture ? format("select (capture {}):", capture) : "select:"_str; auto reg_content = RegisterManager::instance()[reg].values(context); Vector saved_reg{reg_content.begin(), reg_content.end()}; @@ -786,7 +786,7 @@ void select_regex(Context& context, NormalParams params) void split_regex(Context& context, NormalParams params) { const char reg = to_lower(params.reg ? params.reg : '/'); - unsigned capture = (unsigned)params.count; + const int capture = params.count; auto prompt = capture ? format("split (on capture {}):", (int)capture) : "split:"_str; auto reg_content = RegisterManager::instance()[reg].values(context); diff --git a/src/selectors.cc b/src/selectors.cc index 97e7fd33..598aff70 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -841,10 +841,10 @@ template Selection find_next_match(const Buffer&, const Selection&, co using RegexIt = RegexIterator; -void select_all_matches(SelectionList& selections, const Regex& regex, unsigned capture) +void select_all_matches(SelectionList& selections, const Regex& regex, int capture) { - const unsigned mark_count = regex.mark_count(); - if (capture > mark_count) + const int mark_count = (int)regex.mark_count(); + if (capture < 0 or capture > mark_count) throw runtime_error("invalid capture number"); Vector result; @@ -887,9 +887,9 @@ void select_all_matches(SelectionList& selections, const Regex& regex, unsigned selections = SelectionList{buffer, std::move(result)}; } -void split_selections(SelectionList& selections, const Regex& regex, unsigned capture) +void split_selections(SelectionList& selections, const Regex& regex, int capture) { - if (capture > regex.mark_count()) + if (capture < 0 or capture > (int)regex.mark_count()) throw runtime_error("invalid capture number"); Vector result; diff --git a/src/selectors.hh b/src/selectors.hh index 0811b8ae..6933a6b2 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -87,8 +87,8 @@ bool find_match_in_buffer(const Buffer& buffer, const BufferIterator pos, template Selection find_next_match(const Buffer& buffer, const Selection& sel, const Regex& regex, bool& wrapped); -void select_all_matches(SelectionList& selections, const Regex& regex, unsigned capture = 0); -void split_selections(SelectionList& selections, const Regex& separator_regex, unsigned capture = 0); +void select_all_matches(SelectionList& selections, const Regex& regex, int capture = 0); +void split_selections(SelectionList& selections, const Regex& separator_regex, int capture = 0); Selection select_surrounding(const Buffer& buffer, const Selection& selection, StringView opening, StringView closing, int level,