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)); return select<mode>(context, std::bind(sel.func, _1, _2, flags));
} }
static const struct static constexpr struct
{ {
CodepointPair pair; MatchingPair pair;
Codepoint name; Codepoint name;
} surrounding_pairs[] = { } surrounding_pairs[] = {
{ { '(', ')' }, 'b' }, { { '(', ')' }, 'b' },
@ -923,7 +923,7 @@ void select_object(Context& context, NormalParams params)
}; };
for (auto& sur : surrounding_pairs) 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)) (sur.name != 0 and sur.name == c))
return select<mode>(context, std::bind(select_surrounding, _1, _2, return select<mode>(context, std::bind(select_surrounding, _1, _2,
sur.pair, level, flags)); 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, static Optional<Selection> find_surrounding(const Buffer& buffer,
ByteCoord coord, ByteCoord coord,
CodepointPair matching, MatchingPair matching,
ObjectFlags flags, int init_level) ObjectFlags flags, int init_level)
{ {
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 = matching.first != matching.second; const bool nestable = matching.opening != matching.closing;
auto pos = buffer.iterator_at(coord); auto pos = buffer.iterator_at(coord);
Utf8Iterator first = pos; Utf8Iterator first = pos;
if (to_begin) if (to_begin)
@ -94,9 +94,9 @@ static Optional<Selection> find_surrounding(const Buffer& buffer,
int level = nestable ? init_level : 0; int level = nestable ? init_level : 0;
while (first != buffer.begin()) while (first != buffer.begin())
{ {
if (nestable and first != pos and *first == matching.second) if (nestable and first != pos and *first == matching.closing)
++level; ++level;
else if (*first == matching.first) else if (*first == matching.opening)
{ {
if (level == 0) if (level == 0)
break; break;
@ -105,7 +105,7 @@ static Optional<Selection> find_surrounding(const Buffer& buffer,
} }
--first; --first;
} }
if (level != 0 or *first != matching.first) if (level != 0 or *first != matching.opening)
return Optional<Selection>{}; return Optional<Selection>{};
} }
@ -115,9 +115,9 @@ static Optional<Selection> find_surrounding(const Buffer& buffer,
int level = nestable ? init_level : 0; int level = nestable ? init_level : 0;
while (last != buffer.end()) while (last != buffer.end())
{ {
if (nestable and last != pos and *last == matching.first) if (nestable and last != pos and *last == matching.opening)
++level; ++level;
else if (*last == matching.second) else if (*last == matching.closing)
{ {
if (level == 0) if (level == 0)
break; break;
@ -141,10 +141,10 @@ static Optional<Selection> find_surrounding(const Buffer& buffer,
} }
Selection select_surrounding(const Buffer& buffer, const Selection& selection, Selection select_surrounding(const Buffer& buffer, const Selection& selection,
CodepointPair matching, int level, MatchingPair matching, int level,
ObjectFlags flags) ObjectFlags flags)
{ {
const bool nestable = matching.first != matching.second; const bool nestable = matching.opening != matching.closing;
auto pos = selection.cursor(); auto pos = selection.cursor();
if (not nestable or flags & ObjectFlags::Inner) 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); auto c = buffer.byte_at(pos);
if ((flags == ObjectFlags::ToBegin and c == matching.first) or if ((flags == ObjectFlags::ToBegin and c == matching.opening) or
(flags == ObjectFlags::ToEnd and c == matching.second)) (flags == ObjectFlags::ToEnd and c == matching.closing))
++level; ++level;
auto res = find_surrounding(buffer, pos, matching, flags, 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, void split_selections(SelectionList& selections,
const Regex& separator_regex); const Regex& separator_regex);
using CodepointPair = std::pair<Codepoint, Codepoint>; struct MatchingPair { Codepoint opening, closing; };
Selection select_surrounding(const Buffer& buffer, const Selection& selection, Selection select_surrounding(const Buffer& buffer, const Selection& selection,
CodepointPair matching, int level, ObjectFlags flags); MatchingPair matching, int level, ObjectFlags flags);
} }