UNPKG

1.54 kBTypeScriptView Raw
1/**
2 * An interface for a builder object that allows a large text string to be constructed incrementally by appending
3 * small chunks.
4 *
5 * @remarks
6 *
7 * {@link StringBuilder} is the default implementation of this contract.
8 */
9export interface IStringBuilder {
10 /**
11 * Append the specified text to the buffer.
12 */
13 append(text: string): void;
14 /**
15 * Returns a single string containing all the text that was appended to the buffer so far.
16 *
17 * @remarks
18 *
19 * This is a potentially expensive operation.
20 */
21 toString(): string;
22}
23/**
24 * This class allows a large text string to be constructed incrementally by appending small chunks. The final
25 * string can be obtained by calling StringBuilder.toString().
26 *
27 * @remarks
28 * A naive approach might use the `+=` operator to append strings: This would have the downside of copying
29 * the entire string each time a chunk is appended, resulting in `O(n^2)` bytes of memory being allocated
30 * (and later freed by the garbage collector), and many of the allocations could be very large objects.
31 * StringBuilder avoids this overhead by accumulating the chunks in an array, and efficiently joining them
32 * when `getText()` is finally called.
33 */
34export declare class StringBuilder implements IStringBuilder {
35 private _chunks;
36 constructor();
37 /** {@inheritdoc IStringBuilder.append} */
38 append(text: string): void;
39 /** {@inheritdoc IStringBuilder.toString} */
40 toString(): string;
41}
42//# sourceMappingURL=StringBuilder.d.ts.map
\No newline at end of file