Hi klimek,

As suggested in your last mail (Re: [PATCH] Make tooling::Range more
convenient.) I added the predicates to the tooling::Range class.

http://llvm-reviews.chandlerc.com/D1184

Files:
  include/clang/Tooling/Refactoring.h

Index: include/clang/Tooling/Refactoring.h
===================================================================
--- include/clang/Tooling/Refactoring.h
+++ include/clang/Tooling/Refactoring.h
@@ -38,8 +38,27 @@
   Range() : Offset(0), Length(0) {}
   Range(unsigned Offset, unsigned Length) : Offset(Offset), Length(Length) {}
 
+  /// \brief Accessors.
+  /// @{
   unsigned getOffset() const { return Offset; }
   unsigned getLength() const { return Length; }
+  /// @}
+
+  /// \name Range Predicates
+  /// @{
+  /// \brief Whether this range overlaps with \p RHS or not.
+  bool overlaps(Range RHS) const {
+    if ((Offset + Length) <= RHS.Offset || Offset >= (RHS.Offset + RHS.Length))
+      return false;
+    return true;
+  }
+
+  /// \brief Whether this range contains \p RHS or not.
+  bool contains(Range RHS) const {
+    return RHS.Offset >= Offset &&
+           (RHS.Offset + RHS.Length) <= (Offset + Length);
+  }
+  /// @}
 
 private:
   unsigned Offset;
Index: include/clang/Tooling/Refactoring.h
===================================================================
--- include/clang/Tooling/Refactoring.h
+++ include/clang/Tooling/Refactoring.h
@@ -38,8 +38,27 @@
   Range() : Offset(0), Length(0) {}
   Range(unsigned Offset, unsigned Length) : Offset(Offset), Length(Length) {}
 
+  /// \brief Accessors.
+  /// @{
   unsigned getOffset() const { return Offset; }
   unsigned getLength() const { return Length; }
+  /// @}
+
+  /// \name Range Predicates
+  /// @{
+  /// \brief Whether this range overlaps with \p RHS or not.
+  bool overlaps(Range RHS) const {
+    if ((Offset + Length) <= RHS.Offset || Offset >= (RHS.Offset + RHS.Length))
+      return false;
+    return true;
+  }
+
+  /// \brief Whether this range contains \p RHS or not.
+  bool contains(Range RHS) const {
+    return RHS.Offset >= Offset &&
+           (RHS.Offset + RHS.Length) <= (Offset + Length);
+  }
+  /// @}
 
 private:
   unsigned Offset;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to