From 150445df7cb5fe9bd958c592842699533646e2cc Mon Sep 17 00:00:00 2001 From: Julien FAUCHER Date: Mon, 12 Feb 2024 16:46:52 +0100 Subject: [PATCH] Add helper function to determine if a location is in a range (#891) Adds SourceRange::contains(SourceLocation) allowing to know if a source location is within the boundaries of the source range. --- include/slang/text/SourceLocation.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/slang/text/SourceLocation.h b/include/slang/text/SourceLocation.h index 537749af4..ca619ed35 100644 --- a/include/slang/text/SourceLocation.h +++ b/include/slang/text/SourceLocation.h @@ -162,6 +162,9 @@ class SLANG_EXPORT SourceRange { /// @return the end of the range. SourceLocation end() const { return endLoc; } + /// @return true if @a location is within the range, boundaries included. + bool contains(const SourceLocation& loc) const { return loc >= startLoc && loc <= endLoc; } + bool operator==(const SourceRange& rhs) const = default; /// A range that is reserved to represent "no location" at all.