forked from qt-creator/qt-creator
LSP: Add Range::contains(Range)
Change-Id: I762f5582cd00e6ee00a0c345a1b9ba4de8231538 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -312,6 +312,15 @@ Range::Range(const QTextCursor &cursor)
|
||||
setEnd(Position(line - 1, character - 1));
|
||||
}
|
||||
|
||||
bool Range::contains(const Range &other) const
|
||||
{
|
||||
if (start() > other.start())
|
||||
return false;
|
||||
if (end() < other.end())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Range::overlaps(const Range &range) const
|
||||
{
|
||||
return contains(range.start()) || contains(range.end());
|
||||
|
@@ -90,10 +90,20 @@ public:
|
||||
QTextCursor toTextCursor(QTextDocument *doc) const;
|
||||
};
|
||||
|
||||
static bool operator<=(const Position &first, const Position &second)
|
||||
inline bool operator<(const Position &first, const Position &second)
|
||||
{
|
||||
return first.line() < second.line()
|
||||
|| (first.line() == second.line() && first.character() <= second.character());
|
||||
|| (first.line() == second.line() && first.character() < second.character());
|
||||
}
|
||||
|
||||
inline bool operator>(const Position &first, const Position &second)
|
||||
{
|
||||
return second < first;
|
||||
}
|
||||
|
||||
inline bool operator<=(const Position &first, const Position &second)
|
||||
{
|
||||
return !(first > second);
|
||||
}
|
||||
|
||||
class LANGUAGESERVERPROTOCOL_EXPORT Range : public JsonObject
|
||||
@@ -113,6 +123,7 @@ public:
|
||||
void setEnd(const Position &end) { insert(endKey, end); }
|
||||
|
||||
bool contains(const Position &pos) const { return start() <= pos && pos <= end(); }
|
||||
bool contains(const Range &other) const;
|
||||
bool overlaps(const Range &range) const;
|
||||
|
||||
bool isValid() const override
|
||||
|
Reference in New Issue
Block a user