[vala/0.48] vala: Add SourceReference.contains()



commit 51f4da9ff6f23ab1a3c66fdf8f932febd0911b5f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Mar 19 15:58:25 2019 +0100

    vala: Add SourceReference.contains()

 vala/valasourcereference.vala | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
---
diff --git a/vala/valasourcereference.vala b/vala/valasourcereference.vala
index 24aeeda45..d0680f705 100644
--- a/vala/valasourcereference.vala
+++ b/vala/valasourcereference.vala
@@ -58,6 +58,26 @@ public class Vala.SourceReference {
                using_directives = file.current_using_directives;
        }
 
+       /**
+        * Checks if given source location is part of this source reference.
+        *
+        * @param location     a source location
+        * @return             whether this source location is part of this
+        */
+       public bool contains (SourceLocation location) {
+               if (location.line > begin.line && location.line < end.line) {
+                       return true;
+               } else if (location.line == begin.line && location.line == end.line) {
+                       return location.column >= begin.column && location.column <= end.column;
+               } else if (location.line == begin.line) {
+                       return location.column >= begin.column;
+               } else if (location.line == end.line) {
+                       return location.column <= end.column;
+               } else {
+                       return false;
+               }
+       }
+
        /**
         * Returns a string representation of this source reference.
         *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]