Convert CodepointPair to struct MatchingPair

This commit is contained in:
Maxime Coste 2015-03-04 20:47:14 +00:00
parent c0e4268e17
commit bc7c3987e1
3 changed files with 16 additions and 16 deletions

View File

@ -908,9 +908,9 @@ void select_object(Context& context, NormalParams params)
return select<mode>(context, std::bind(sel.func, _1, _2, flags));
}
static const struct
static constexpr struct
{
CodepointPair pair;
MatchingPair pair;
Codepoint name;
} surrounding_pairs[] = {
{ { '(', ')' }, 'b' },
@ -923,7 +923,7 @@ void select_object(Context& context, NormalParams params)
};
for (auto& sur : surrounding_pairs)
{
if (sur.pair.first == c or sur.pair.second == c or
if (sur.pair.opening == c or sur.pair.closing == c or
(sur.name != 0 and sur.name == c))
return select<mode>(context, std::bind(select_surrounding, _1, _2,
sur.pair, level, flags));

View File

@ -81,12 +81,12 @@ Selection select_matching(const Buffer& buffer, const Selection& selection)
static Optional<Selection> find_surrounding(const Buffer& buffer,
ByteCoord coord,
CodepointPair matching,
MatchingPair matching,
ObjectFlags flags, int init_level)
{
const bool to_begin = flags & ObjectFlags::ToBegin;
const bool to_end = flags & ObjectFlags::ToEnd;
const bool nestable = matching.first != matching.second;
const bool nestable = matching.opening != matching.closing;
auto pos = buffer.iterator_at(coord);
Utf8Iterator first = pos;
if (to_begin)
@ -94,9 +94,9 @@ static Optional<Selection> find_surrounding(const Buffer& buffer,
int level = nestable ? init_level : 0;
while (first != buffer.begin())
{
if (nestable and first != pos and *first == matching.second)
if (nestable and first != pos and *first == matching.closing)
++level;
else if (*first == matching.first)
else if (*first == matching.opening)
{
if (level == 0)
break;
@ -105,7 +105,7 @@ static Optional<Selection> find_surrounding(const Buffer& buffer,
}
--first;
}
if (level != 0 or *first != matching.first)
if (level != 0 or *first != matching.opening)
return Optional<Selection>{};
}
@ -115,9 +115,9 @@ static Optional<Selection> find_surrounding(const Buffer& buffer,
int level = nestable ? init_level : 0;
while (last != buffer.end())
{
if (nestable and last != pos and *last == matching.first)
if (nestable and last != pos and *last == matching.opening)
++level;
else if (*last == matching.second)
else if (*last == matching.closing)
{
if (level == 0)
break;
@ -141,10 +141,10 @@ static Optional<Selection> find_surrounding(const Buffer& buffer,
}
Selection select_surrounding(const Buffer& buffer, const Selection& selection,
CodepointPair matching, int level,
MatchingPair matching, int level,
ObjectFlags flags)
{
const bool nestable = matching.first != matching.second;
const bool nestable = matching.opening != matching.closing;
auto pos = selection.cursor();
if (not nestable or flags & ObjectFlags::Inner)
{
@ -154,8 +154,8 @@ Selection select_surrounding(const Buffer& buffer, const Selection& selection,
}
auto c = buffer.byte_at(pos);
if ((flags == ObjectFlags::ToBegin and c == matching.first) or
(flags == ObjectFlags::ToEnd and c == matching.second))
if ((flags == ObjectFlags::ToBegin and c == matching.opening) or
(flags == ObjectFlags::ToEnd and c == matching.closing))
++level;
auto res = find_surrounding(buffer, pos, matching, flags, level);

View File

@ -296,9 +296,9 @@ void select_all_matches(SelectionList& selections,
void split_selections(SelectionList& selections,
const Regex& separator_regex);
using CodepointPair = std::pair<Codepoint, Codepoint>;
struct MatchingPair { Codepoint opening, closing; };
Selection select_surrounding(const Buffer& buffer, const Selection& selection,
CodepointPair matching, int level, ObjectFlags flags);
MatchingPair matching, int level, ObjectFlags flags);
}