/** * Copyright 2017 Matt Acosta * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { IComparable, IEquatable } from '@mattacosta/php-common'; /** * Represents a region of text. * * Text span comparison methods: * * | | contains | overlaps | intersects | * |------------|:--------:|:--------:|:----------:| * | `-aaa----` | no | no | yes | * | `----bbb-` | | | | * | `-aaa----` | no | yes | yes | * | `---bbb--` | | | | * | `--aaaa--` | yes | yes | yes | * | `--bbbb--` | | | | */ export declare class TextSpan implements IComparable, IEquatable { /** * The number of characters in the span. */ readonly length: number; /** * The starting location of the span. */ readonly start: number; /** * Constructs a `TextSpan` object. * * @param {number} start * The starting location of the span. * @param {number} length * The number of characters in the span. */ constructor(start: number, length: number); /** * Creates a `TextSpan` using starting and ending locations. * * @param {number} start * The starting location of the span. * @param {number} end * The ending location of the span. */ static fromBounds(start: number, end: number): TextSpan; /** * Gets the ending location of the span. */ get end(): number; /** * Determines if the number of characters in the span is zero. */ get isEmpty(): boolean; /** * @inheritDoc */ compareTo(span: TextSpan): number; /** * Determines if the given span is completely within this span, or if an * offset is within the bounds of this span (`start` inclusive). */ contains(position: TextSpan | number): boolean; /** * @inheritDoc */ equals(span: TextSpan): boolean; /** * Finds the intersecting region of this span and a given span. * * Text spans intersect if both share a common region, or if the end of one * span is the same as the start of the other. * * @return {TextSpan|null} * The intersecting region of the spans, or `null` if the spans did not * intersect. */ intersection(span: TextSpan): TextSpan | null; /** * Determines if a given span intersects with this span, or if an offset is * within the bounds of this span (`start` and `end` inclusive). */ intersectsWith(position: TextSpan | number): boolean; /** * Finds the overlapping region of this span and a given span. * * @return {TextSpan|null} * The overlapping region of the spans, or `null` if the spans did not * overlap. */ overlap(span: TextSpan): TextSpan | null; /** * Determines if the given span overlaps with this span. */ overlapsWith(span: TextSpan): boolean; }