Slight cleanup of select_surrounding implementation
This commit is contained in:
parent
c8257a58a5
commit
43d470f286
|
@ -314,12 +314,13 @@ Optional<Iterator> find_closing(Iterator pos, Iterator end,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Iterator>
|
template<typename Container, typename Iterator>
|
||||||
Optional<std::pair<Iterator, Iterator>>
|
Optional<std::pair<Iterator, Iterator>>
|
||||||
find_surrounding(Iterator begin, Iterator end,
|
find_surrounding(const Container& container, Iterator pos,
|
||||||
Iterator pos, StringView opening, StringView closing,
|
StringView opening, StringView closing,
|
||||||
ObjectFlags flags, int init_level)
|
ObjectFlags flags, int init_level)
|
||||||
{
|
{
|
||||||
|
using std::begin; using std::end;
|
||||||
const bool to_begin = flags & ObjectFlags::ToBegin;
|
const bool to_begin = flags & ObjectFlags::ToBegin;
|
||||||
const bool to_end = flags & ObjectFlags::ToEnd;
|
const bool to_end = flags & ObjectFlags::ToEnd;
|
||||||
const bool nestable = opening != closing;
|
const bool nestable = opening != closing;
|
||||||
|
@ -328,7 +329,7 @@ find_surrounding(Iterator begin, Iterator end,
|
||||||
if (to_begin and opening != *pos)
|
if (to_begin and opening != *pos)
|
||||||
{
|
{
|
||||||
using RevIt = std::reverse_iterator<Iterator>;
|
using RevIt = std::reverse_iterator<Iterator>;
|
||||||
auto res = find_closing(RevIt{pos+1}, RevIt{begin},
|
auto res = find_closing(RevIt{pos+1}, RevIt{begin(container)},
|
||||||
closing | reverse(), opening | reverse(),
|
closing | reverse(), opening | reverse(),
|
||||||
init_level, nestable);
|
init_level, nestable);
|
||||||
if (not res)
|
if (not res)
|
||||||
|
@ -340,7 +341,7 @@ find_surrounding(Iterator begin, Iterator end,
|
||||||
auto last = pos;
|
auto last = pos;
|
||||||
if (to_end)
|
if (to_end)
|
||||||
{
|
{
|
||||||
auto res = find_closing(pos, end, opening, closing,
|
auto res = find_closing(pos, end(container), opening, closing,
|
||||||
init_level, nestable);
|
init_level, nestable);
|
||||||
if (not res)
|
if (not res)
|
||||||
return {};
|
return {};
|
||||||
|
@ -359,17 +360,6 @@ find_surrounding(Iterator begin, Iterator end,
|
||||||
: std::pair<Iterator, Iterator>{last, first};
|
: std::pair<Iterator, Iterator>{last, first};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Container, typename Iterator>
|
|
||||||
Optional<std::pair<Iterator, Iterator>>
|
|
||||||
find_surrounding(const Container& container, Iterator pos,
|
|
||||||
StringView opening, StringView closing,
|
|
||||||
ObjectFlags flags, int init_level)
|
|
||||||
{
|
|
||||||
using std::begin; using std::end;
|
|
||||||
return find_surrounding(begin(container), end(container), pos,
|
|
||||||
opening, closing, flags, init_level);
|
|
||||||
}
|
|
||||||
|
|
||||||
Optional<Selection>
|
Optional<Selection>
|
||||||
select_surrounding(const Context& context, const Selection& selection,
|
select_surrounding(const Context& context, const Selection& selection,
|
||||||
StringView opening, StringView closing, int level,
|
StringView opening, StringView closing, int level,
|
||||||
|
|
|
@ -109,8 +109,8 @@ void split_selections(SelectionList& selections, const Regex& regex, int capture
|
||||||
|
|
||||||
Optional<Selection>
|
Optional<Selection>
|
||||||
select_surrounding(const Context& context, const Selection& selection,
|
select_surrounding(const Context& context, const Selection& selection,
|
||||||
StringView opening, StringView closing, int level,
|
StringView opening, StringView closing, int level,
|
||||||
ObjectFlags flags);
|
ObjectFlags flags);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user