forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextBuilder.ts
More file actions
41 lines (33 loc) · 1.06 KB
/
Copy pathtextBuilder.ts
File metadata and controls
41 lines (33 loc) · 1.06 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { isWhiteSpace } from './characters';
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
export class TextBuilder {
private segments: string[] = [];
public getText(): string {
if (this.isLastWhiteSpace()) {
this.segments.pop();
}
return this.segments.join('');
}
public softAppendSpace(): void {
if (!this.isLastWhiteSpace() && this.segments.length > 0) {
this.segments.push(' ');
}
}
public append(text: string): void {
this.segments.push(text);
}
private isLastWhiteSpace(): boolean {
return this.segments.length > 0 && this.isWhitespace(this.segments[this.segments.length - 1]);
}
private isWhitespace(s: string): boolean {
for (let i = 0; i < s.length; i += 1) {
if (!isWhiteSpace(s.charCodeAt(i))) {
return false;
}
}
return true;
}
}