/** * Returns the overlap with the given span, or null if there is no overlap. * @param span The span to check. */ public TextSpan overlap(TextSpan span) { var overlapStart = Math.Max(this._start, span._start); var overlapEnd = Math.Min(this.end(), span.end()); if (overlapStart < overlapEnd) { return TextSpan.fromBounds(overlapStart, overlapEnd); } return null; }
/** * Determines whether the given span overlaps this span. Two spans are considered to overlap * if they have positions in common and neither is empty. Empty spans do not overlap with any * other span. Returns true if the spans overlap, false otherwise. * @param span The span to check. */ public bool overlapsWith(TextSpan span) { var overlapStart = Math.Max(this._start, span._start); var overlapEnd = Math.Min(this.end(), span.end()); return overlapStart < overlapEnd; }
/** * Returns the intersection with the given span, or null if there is no intersection. * @param span The span to check. */ public TextSpan intersection(TextSpan span) { var intersectStart = Math.Max(this._start, span._start); var intersectEnd = Math.Min(this.end(), span.end()); if (intersectStart <= intersectEnd) { return TextSpan.fromBounds(intersectStart, intersectEnd); } return null; }
/** * Determines whether span falls completely within this span. Returns true if the specified span falls completely within this span, otherwise false. * @param span The span to check. */ public bool containsTextSpan(TextSpan span) { return span._start >= this._start && span.end() <= this.end(); }
/** * Determines whether span intersects this span. Two spans are considered to * intersect if they have positions in common or the end of one span * coincides with the start of the other span. Returns true if the spans intersect, false otherwise. * @param The span to check. */ public bool intersectsWithTextSpan(TextSpan span) { return span._start <= this.end() && span.end() >= this._start; }