stringBuilder.ts ×14

Frontier kind: Code frontier

unlabeled · c_660e05a841ac

972 tests · 5532 LOC · 29 files · introduces 0 tests · 49 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
14 ranges49 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
811 ranges5532 lines · 29 files · Browse complete extent
All tests (intent)
972 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 49 introduced LOC across 14 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/core/stringBuilder.ts 49 introduced LOC · 14 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- stringBuilder.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import * as strings from '../../../base/common/strings.js';
7 > import * as platform from '../../../base/common/platform.js';
8 > import * as buffer from '../../../base/common/buffer.js';
9 >
10 > let _utf16LE_TextDecoder: TextDecoder | null;
11 function getUTF16LE_TextDecoder(): TextDecoder {
12 if (!_utf16LE_TextDecoder) {
15 return _utf16LE_TextDecoder;
16 }
18 > let _utf16BE_TextDecoder: TextDecoder | null;
19 function getUTF16BE_TextDecoder(): TextDecoder {
20 if (!_utf16BE_TextDecoder) {
23 return _utf16BE_TextDecoder;
24 }
26 > let _platformTextDecoder: TextDecoder | null;
27 > export function getPlatformTextDecoder(): TextDecoder {
28 if (!_platformTextDecoder) {
29 _platformTextDecoder = platform.isLittleEndian() ? getUTF16LE_TextDecoder() : getUTF16BE_TextDecoder();
31 return _platformTextDecoder;
32 }
34 > export function decodeUTF16LE(source: Uint8Array, offset: number, len: number): string {
35 const view = new Uint16Array(source.buffer, offset, len);
36 if (len > 0 && (view[0] === 0xFEFF || view[0] === 0xFFFE)) {
43 return getUTF16LE_TextDecoder().decode(view);
44 }
46 function compatDecodeUTF16LE(source: Uint8Array, offset: number, len: number): string {
47 const result: string[] = [];
53 return result.join('');
54 }
56 > export class StringBuilder {
57 >
58 > private readonly _capacity: number;
59 > private readonly _buffer: Uint16Array;
60 >
61 > private _completedStrings: string[] | null;
62 > private _bufferLength: number;
63 >
64 > constructor(capacity: number) {
65 this._capacity = capacity | 0;
66 this._buffer = new Uint16Array(this._capacity);
69 this._bufferLength = 0;
70 }
72 > public reset(): void {
73 this._completedStrings = null;
74 this._bufferLength = 0;
75 }
77 > public build(): string {
78 if (this._completedStrings !== null) {
79 this._flushBuffer();
82 return this._buildBuffer();
83 }
85 > private _buildBuffer(): string {
86 if (this._bufferLength === 0) {
87 return '';
91 return getPlatformTextDecoder().decode(view);
92 }
94 > private _flushBuffer(): void {
95 const bufferString = this._buildBuffer();
96 this._bufferLength = 0;
102 }
103 }
105 > /**
106 > * Append a char code (<2^16)
107 > */
108 > public appendCharCode(charCode: number): void {
109 const remainingSpace = this._capacity - this._bufferLength;
110
117 this._buffer[this._bufferLength++] = charCode;
118 }
120 > /**
121 > * Append an ASCII char code (<2^8)
122 > */
123 > public appendASCIICharCode(charCode: number): void {
124 if (this._bufferLength === this._capacity) {
125 // buffer is full
128 this._buffer[this._bufferLength++] = charCode;
129 }
131 > public appendString(str: string): void {
132 const strLen = str.length;
133