Skip to content

Commit

Permalink
Add helper function to determine if a location is in a range (#891)
Browse files Browse the repository at this point in the history
Adds SourceRange::contains(SourceLocation) allowing to know if a source
location is within the boundaries of the source range.
  • Loading branch information
suzizecat authored Feb 12, 2024
1 parent ac5989e commit 150445d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/slang/text/SourceLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 150445d

Please sign in to comment.