forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextFactory.ts
More file actions
69 lines (53 loc) · 2.05 KB
/
Copy pathtextFactory.ts
File metadata and controls
69 lines (53 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
///<reference path='references.ts' />
module TypeScript.SimpleText {
class SimpleStringText implements ISimpleText {
private _lineMap: LineMap = undefined;
constructor(private value: string) {
}
public length(): number {
return this.value.length;
}
public substr(start: number, length: number): string {
var val = this.value;
return start === 0 && length == val.length
? val
: val.substr(start, length);
}
public charCodeAt(index: number): number {
return this.value.charCodeAt(index);
}
public lineMap(): LineMap {
if (!this._lineMap) {
this._lineMap = LineMap1.fromString(this.value);
}
return this._lineMap;
}
}
// Class which wraps a host IScriptSnapshot and exposes an ISimpleText for newer compiler code.
class SimpleScriptSnapshotText implements ISimpleText {
private _lineMap: LineMap = undefined;
constructor(public scriptSnapshot: IScriptSnapshot) {
}
public charCodeAt(index: number): number {
return this.scriptSnapshot.getText(index, index + 1).charCodeAt(0);
}
public length(): number {
return this.scriptSnapshot.getLength();
}
public substr(start: number, length: number): string {
return this.scriptSnapshot.getText(start, start + length);
}
public lineMap(): LineMap {
if (!this._lineMap) {
this._lineMap = new LineMap(() => this.scriptSnapshot.getLineStartPositions(), this.length());
}
return this._lineMap;
}
}
export function fromString(value: string): ISimpleText {
return new SimpleStringText(value);
}
export function fromScriptSnapshot(scriptSnapshot: IScriptSnapshot): ISimpleText {
return new SimpleScriptSnapshotText(scriptSnapshot);
}
}