/** * Copyright 2017 Matt Acosta * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Encoding } from './Encoding'; import { ISourceText } from './ISourceText'; /** * @todo Document `SourceTextBuilder`. */ export declare class SourceTextBuilder { /** * The minimum length of a rebuilt segment. Defaults to 4KB. * * @todo Experimental. */ protected static MinSegmentLength: number; /** * The maximum length of a rebuilt segment. Defaults to 16MB. * * @todo Experimental. */ protected static MaxSegmentLength: number; /** * The number of segments for an optimized rebuild. Defaults to 16. * * @todo Experimental. */ protected static ReducedSegmentTarget: number; /** * The maximum number of segments before the text is considered to be too * fragmented. Defaults to 64. * * @todo Experimental. */ protected static SegmentLimit: number; /** * The original encoding of the source text. */ protected readonly encoding: Encoding; /** * The current length of the source text. */ protected length: number; /** * The text segments used to create the source text. */ protected segments: ISourceText[]; /** * The number of unique sources used to create the source text. */ protected sourceCount: number; /** * The total length of the unique sources used to create the source text. */ protected sourceLength: number; /** * A `Set` containing the unique sources used to create the source text. */ protected uniqueSources: Set; /** * Constructs a `SourceTextBuilder` object. * * @param {Encoding} encoding * The original encoding of the source text. */ constructor(encoding: Encoding); /** * Appends a text segment to the source text. * * @param {ISourceText} segment * The text segment to append. */ append(segment: ISourceText): void; /** * Removes all segments from the builder. */ clear(): void; /** * Creates a source text object from the text segments given to the builder. * * @return {ISourceText} * A new source text object. */ toSourceText(): ISourceText; /** * Stores the underlying source used by a segment, if it is unique to the text * being built. Extending classes may override this method to change the * optimization strategy of custom `ISourceText` implementations. */ protected addSource(segment: ISourceText): void; /** * Reduces the number of segments used by the source text being created. * * @param {number} targetLength * The ideal length of each new segment. */ protected reduceSegments(targetLength: number): void; /** * Removes deleted text from each segment. */ protected trimSegments(): void; /** * Determines how many segments will be required to store text using the * given segment length. */ private computeReducedSegmentCount; /** * Determines the segment length needed to bring the overall number of * segments below a target count. */ private computeReducedSegmentLength; }