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 {};
|
||||
}
|
||||
|
||||
template<typename Iterator>
|
||||
template<typename Container, typename Iterator>
|
||||
Optional<std::pair<Iterator, Iterator>>
|
||||
find_surrounding(Iterator begin, Iterator end,
|
||||
Iterator pos, StringView opening, StringView closing,
|
||||
find_surrounding(const Container& container, Iterator pos,
|
||||
StringView opening, StringView closing,
|
||||
ObjectFlags flags, int init_level)
|
||||
{
|
||||
using std::begin; using std::end;
|
||||
const bool to_begin = flags & ObjectFlags::ToBegin;
|
||||
const bool to_end = flags & ObjectFlags::ToEnd;
|
||||
const bool nestable = opening != closing;
|
||||
|
@ -328,7 +329,7 @@ find_surrounding(Iterator begin, Iterator end,
|
|||
if (to_begin and opening != *pos)
|
||||
{
|
||||
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(),
|
||||
init_level, nestable);
|
||||
if (not res)
|
||||
|
@ -340,7 +341,7 @@ find_surrounding(Iterator begin, Iterator end,
|
|||
auto last = pos;
|
||||
if (to_end)
|
||||
{
|
||||
auto res = find_closing(pos, end, opening, closing,
|
||||
auto res = find_closing(pos, end(container), opening, closing,
|
||||
init_level, nestable);
|
||||
if (not res)
|
||||
return {};
|
||||
|
@ -359,17 +360,6 @@ find_surrounding(Iterator begin, Iterator end,
|
|||
: 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>
|
||||
select_surrounding(const Context& context, const Selection& selection,
|
||||
StringView opening, StringView closing, int level,
|
||||
|
|
Loading…
Reference in New Issue
Block a user