MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / readString

Function readString

src/resolution/dart-libraries.ts:113–150  ·  view source on GitHub ↗

The string literal at `i` — `'…'`, `"…"`, triple-quoted or raw — as its value and the index past it, or null.

(src: string, i: number)

Source from the content-addressed store, hash-verified

111
112/** The string literal at `i` — `'…'`, `"…"`, triple-quoted or raw — as its value and the index past it, or null. */
113function readString(src: string, i: number): { value: string; end: number } | null {
114 let raw = false;
115 if (src[i] === 'r' && (src[i + 1] === "'" || src[i + 1] === '"')) {
116 raw = true;
117 i++;
118 }
119 const quote = src[i];
120 if (quote !== "'" && quote !== '"') return null;
121 const close = src.startsWith(quote.repeat(3), i) ? quote.repeat(3) : quote;
122 let j = i + close.length;
123 let value = '';
124 while (j < src.length) {
125 if (src.startsWith(close, j)) return { value, end: j + close.length };
126 const c = src[j]!;
127 if (c === '\n' && close.length === 1) return null;
128 if (c === '\\' && !raw) {
129 value += src[j + 1] ?? '';
130 j += 2;
131 } else if (c === '$' && !raw && src[j + 1] === '{') {
132 let depth = 1;
133 j += 2;
134 while (j < src.length && depth > 0) {
135 const inner = readString(src, j);
136 if (inner) {
137 j = inner.end;
138 continue;
139 }
140 if (src[j] === '{') depth++;
141 else if (src[j] === '}') depth--;
142 j++;
143 }
144 } else {
145 value += c;
146 j++;
147 }
148 }
149 return null;
150}
151
152/** The index past the balanced `open` … `close` group at `i`, strings and comments skipped; -1 if it never closes. */
153function skipGroup(src: string, i: number, open: string, close: string): number {

Callers 2

skipGroupFunction · 0.85
readDirectiveTokensFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected