TextEditor: Provide a function for inserting a parenthesis

... into a sorted list.

Change-Id: Ibc39a345425945437cc8b8d9237589746143b2d9
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-09-24 12:08:33 +02:00
parent 421e06393f
commit 47cd1def7a
4 changed files with 11 additions and 14 deletions

View File

@@ -698,4 +698,11 @@ bool Parenthesis::operator==(const Parenthesis &other) const
return pos == other.pos && chr == other.chr && source == other.source && type == other.type;
}
void insertSorted(Parentheses &list, const Parenthesis &elem)
{
const auto it = std::lower_bound(list.begin(), list.end(), elem,
[](const auto &p1, const auto &p2) { return p1.pos < p2.pos; });
list.insert(it, elem);
}
} // namespace TextEditor