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

Function stripPhp

src/resolution/strip-comments.ts:272–328  ·  view source on GitHub ↗
(src: string)

Source from the content-addressed store, hash-verified

270// ---------- PHP ----------
271
272function stripPhp(src: string): string {
273 const out = src.split('');
274 let i = 0;
275 const n = src.length;
276
277 while (i < n) {
278 const c = src[i]!;
279 const c2 = src[i + 1] ?? '';
280
281 // Block comment
282 if (c === '/' && c2 === '*') {
283 const start = i;
284 i += 2;
285 while (i < n && !(src[i] === '*' && src[i + 1] === '/')) i++;
286 if (i < n) i += 2;
287 blankRange(out, start, i, src);
288 continue;
289 }
290
291 // // line comment
292 if (c === '/' && c2 === '/') {
293 const start = i;
294 while (i < n && src[i] !== '\n') i++;
295 blankRange(out, start, i, src);
296 continue;
297 }
298
299 // # line comment (PHP supports both)
300 if (c === '#') {
301 const start = i;
302 while (i < n && src[i] !== '\n') i++;
303 blankRange(out, start, i, src);
304 continue;
305 }
306
307 // String literals: ', ", ` (PHP doesn't really use backticks for strings,
308 // but it does have shell-exec backticks; treating as a string is fine here)
309 if (c === '"' || c === "'" || c === '`') {
310 const quote = c;
311 i++;
312 while (i < n && src[i] !== quote) {
313 if (src[i] === '\\' && i + 1 < n) {
314 i += 2;
315 continue;
316 }
317 if (src[i] === '\n') break;
318 i++;
319 }
320 if (i < n && src[i] === quote) i++;
321 continue;
322 }
323
324 i++;
325 }
326
327 return out.join('');
328}
329

Callers 1

stripCommentsForRegexFunction · 0.85

Calls 2

blankRangeFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected