MCPcopy Create free account
hub / github.com/angular/angular / getLineStarts

Function getLineStarts

packages/compiler-cli/preprocessor/src/tcb_util.ts:16–41  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

14const MAX_CACHE_SIZE = 10;
15
16export function getLineStarts(content: string): number[] {
17 let lineStarts = lineStartsCache.get(content);
18 if (lineStarts) {
19 // LRU: delete and re-set to move to end
20 lineStartsCache.delete(content);
21 lineStartsCache.set(content, lineStarts);
22 return lineStarts;
23 }
24
25 lineStarts = [0];
26 let pos = 0;
27 while ((pos = content.indexOf('\n', pos)) !== -1) {
28 pos++;
29 lineStarts.push(pos);
30 }
31
32 if (lineStartsCache.size >= MAX_CACHE_SIZE) {
33 const firstKey = lineStartsCache.keys().next().value;
34 if (firstKey !== undefined) {
35 lineStartsCache.delete(firstKey);
36 }
37 }
38 lineStartsCache.set(content, lineStarts);
39
40 return lineStarts;
41}
42
43export function positionToOffset(
44 content: string,

Callers 2

positionToOffsetFunction · 0.85
offsetToPositionFunction · 0.85

Calls 7

indexOfMethod · 0.80
getMethod · 0.65
setMethod · 0.65
keysMethod · 0.65
deleteMethod · 0.45
pushMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected