import { assert } from '../../utils/assert' ; /**
 * A general purpose range implementation.
 * Is offset/length based in contrast to `vscode.Range` which is line/column based.
 */ export class Range { constructor ( readonly offset , readonly length ) { assert ( ( ) => length >= 0 ) ; } contains ( offset ) { return this . offset <= offset && offset <= this . offsetEnd ; } get offsetEnd ( ) : number { return this . offset + this . length - 1 ; } get isEmpty ( ) : boolean { return this . length === 0 ; } toString ( ) { return `[${ this . offset }, +${ this . length })` ; } move ( delta ) { return new Range ( this . offset + delta , this . length ) ; } moveKeepEnd ( delta ) { assert ( ( ) => delta <= this . length ) ; const result = new Range ( this . offset + delta , this . length - delta ) ; assert ( ( ) => result . offsetEnd === this . offsetEnd ) ; return result ; } moveEnd ( delta ) { return new Range ( this . offset , this . length + delta ) ; } withLength ( newLength ) { return new Range ( this . offset , newLength ) ; } containsRange ( other ) { return this . offset <= other . offset && other . offsetEnd <= this . offsetEnd ; } /**
     * Check whether this range if after `range`.
     */ isAfter ( range ) { return range . offsetEnd < this . offset ; } /**
     * Check whether this range if before `range`.
     */ isBefore ( range ) { return range . offset > this . offsetEnd ; } }