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

Function offsetToPosition

packages/compiler-cli/preprocessor/src/tcb_util.ts:75–97  ·  view source on GitHub ↗
(
  content: string,
  offset: number,
)

Source from the content-addressed store, hash-verified

73}
74
75export function offsetToPosition(
76 content: string,
77 offset: number,
78): {line: number; character: number} {
79 offset = Math.min(content.length, Math.max(0, offset)); // Clamp offset to content length
80 const lineStarts = getLineStarts(content);
81 let low = 0;
82 let high = lineStarts.length - 1;
83 while (low <= high) {
84 const mid = (low + high) >>> 1; // Use bitwise shift
85 if (lineStarts[mid] <= offset) {
86 low = mid + 1;
87 } else {
88 high = mid - 1;
89 }
90 }
91 const line = high;
92 const lineStart = lineStarts[line];
93 return {
94 line,
95 character: offset - lineStart,
96 };
97}
98
99/**
100 * Determines whether a declaration metadata requires inline handling due to not being exported

Calls 3

getLineStartsFunction · 0.85
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected