From: Rico Tzschichholz Date: Tue, 19 Mar 2019 14:58:25 +0000 (+0100) Subject: vala: Add SourceReference.contains() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb3c0947d572573a918624228fd7f9078c77a576;p=thirdparty%2Fvala.git vala: Add SourceReference.contains() --- 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. *