// Empty reports whether the Range is an empty selection. func (rng Range) Empty() bool { … } // Empty reports whether the Location is an empty selection. func (loc Location) Empty() bool { … } // CompareLocation defines a three-valued comparison over locations, // lexicographically ordered by (URI, Range). func CompareLocation(x, y Location) int { … } // CompareRange returns -1 if a is before b, 0 if a == b, and 1 if a is after b. // // A range a is defined to be 'before' b if a.Start is before b.Start, or // a.Start == b.Start and a.End is before b.End. func CompareRange(a, b Range) int { … } // ComparePosition returns -1 if a is before b, 0 if a == b, and 1 if a is after b. func ComparePosition(a, b Position) int { … } // Intersect reports whether x and y intersect. // // Two non-empty half-open integer intervals intersect iff: // // y.start < x.end && x.start < y.end // // Mathematical conventional views an interval as a set of integers. // An empty interval is the empty set, so its intersection with any // other interval is empty, and thus an empty interval does not // intersect any other interval. // // However, this function uses a looser definition appropriate for // text selections: if either x or y is empty, it uses <= operators // instead, so an empty range within or abutting a non-empty range is // considered to overlap it, and an empty range overlaps itself. // // This handles the common case in which there is no selection, but // the cursor is at the start or end of an expression and the caller // wants to know whether the cursor intersects the range of the // expression. The answer in this case should be yes, even though the // selection is empty. Similarly the answer should also be yes if the // cursor is properly within the range of the expression. But a // non-empty selection abutting the expression should not be // considered to intersect it. func Intersect(x, y Range) bool { … } // Format implements fmt.Formatter. // // Note: Formatter is implemented instead of Stringer (presumably) for // performance reasons, though it is not clear that it matters in practice. func (r Range) Format(f fmt.State, _ rune) { … } // Format implements fmt.Formatter. // // See Range.Format for discussion of why the Formatter interface is // implemented rather than Stringer. func (p Position) Format(f fmt.State, _ rune) { … } // UTF16Len returns the number of codes in the UTF-16 transcoding of s. func UTF16Len(s []byte) int { … }