UNPKG

2.8 kBTypeScriptView Raw
1/**
2 * Text coordinates represented as a line number and column number.
3 *
4 * @remarks
5 * The first character in a file is considered to be in column 1 of line 1.
6 * The location with column 0 and line 0 is used to represent an empty, unspecified,
7 * or unknown location.
8 */
9export interface ITextLocation {
10 line: number;
11 column: number;
12}
13/**
14 * Efficiently references a range of text from a string buffer.
15 */
16export declare class TextRange {
17 /**
18 * Used to represent an empty or unknown range.
19 */
20 static readonly empty: TextRange;
21 /**
22 * The starting index into the associated text buffer.
23 *
24 * @remarks
25 * The text range corresponds to the `range.buffer.substring(range.pos, range.end)`.
26 */
27 readonly pos: number;
28 /**
29 * The (non-inclusive) ending index for the associated text buffer.
30 *
31 * @remarks
32 * The text range corresponds to the `range.buffer.substring(range.pos, range.end)`.
33 */
34 readonly end: number;
35 /**
36 * The string buffer that the `pos` and `end` indexes refer to.
37 */
38 readonly buffer: string;
39 private constructor();
40 /**
41 * Constructs a TextRange that corresponds to an entire string object.
42 */
43 static fromString(buffer: string): TextRange;
44 /**
45 * Constructs a TextRange that corresponds to an entire string object.
46 */
47 static fromStringRange(buffer: string, pos: number, end: number): TextRange;
48 /**
49 * Returns the length of the text range.
50 * @remarks
51 * This value is calculated as the `end` property minus the `pos` property.
52 */
53 get length(): number;
54 /**
55 * Constructs a TextRange that corresponds to a different range of an existing buffer.
56 */
57 getNewRange(pos: number, end: number): TextRange;
58 /**
59 * Returns true if the length of the range is zero. Note that the object reference may not
60 * be equal to `TextRange.empty`, and the buffer may be different.
61 */
62 isEmpty(): boolean;
63 /**
64 * Returns the range from the associated string buffer.
65 */
66 toString(): string;
67 /**
68 * Returns a debugging dump of the range, indicated via custom delimiters.
69 * @remarks
70 * For example if the delimiters are "[" and "]", and the range is 3..5 inside "1234567",
71 * then the output would be "12[345]67".
72 */
73 getDebugDump(posDelimiter: string, endDelimiter: string): string;
74 /**
75 * Calculates the line and column number for the specified offset into the buffer.
76 *
77 * @remarks
78 * This is a potentially expensive operation.
79 *
80 * @param index - an integer offset
81 * @param buffer - the buffer
82 */
83 getLocation(index: number): ITextLocation;
84 private _validateBounds;
85}
86//# sourceMappingURL=TextRange.d.ts.map
\No newline at end of file