(src: string, allowSingleQuoteStrings: boolean)
| 264 | // ---------- C-style (JS/TS/Java/C#/Swift) ---------- |
| 265 | |
| 266 | function stripCStyle(src: string, allowSingleQuoteStrings: boolean): string { |
| 267 | const out = src.split(''); |
| 268 | let i = 0; |
| 269 | const n = src.length; |
| 270 | |
| 271 | while (i < n) { |
| 272 | const c = src[i]!; |
| 273 | const c2 = src[i + 1] ?? ''; |
| 274 | |
| 275 | // Block comment |
| 276 | if (c === '/' && c2 === '*') { |
| 277 | const start = i; |
| 278 | i += 2; |
| 279 | while (i < n && !(src[i] === '*' && src[i + 1] === '/')) i++; |
| 280 | if (i < n) i += 2; |
| 281 | blankRange(out, start, i, src); |
| 282 | continue; |
| 283 | } |
| 284 | |
| 285 | // Line comment |
| 286 | if (c === '/' && c2 === '/') { |
| 287 | const start = i; |
| 288 | while (i < n && src[i] !== '\n') i++; |
| 289 | blankRange(out, start, i, src); |
| 290 | continue; |
| 291 | } |
| 292 | |
| 293 | // String literals |
| 294 | if (c === '"' || (allowSingleQuoteStrings && c === "'") || c === '`') { |
| 295 | const quote = c; |
| 296 | i++; |
| 297 | while (i < n && src[i] !== quote) { |
| 298 | if (src[i] === '\\' && i + 1 < n) { |
| 299 | i += 2; |
| 300 | continue; |
| 301 | } |
| 302 | // Template literal can span lines; regular strings break on newline (treat as unterminated) |
| 303 | if (quote !== '`' && src[i] === '\n') break; |
| 304 | i++; |
| 305 | } |
| 306 | if (i < n && src[i] === quote) i++; |
| 307 | continue; |
| 308 | } |
| 309 | |
| 310 | i++; |
| 311 | } |
| 312 | |
| 313 | return out.join(''); |
| 314 | } |
| 315 | |
| 316 | // ---------- PHP ---------- |
| 317 |
no test coverage detected