* Disambiguate multiple `"uuid":"<36>","timestamp":"` matches in one line by * finding the one at JSON nesting depth 1. String-aware brace counter: * `{`/`}` inside string values don't count; `\"` and `\\` inside strings are * handled. Candidates is sorted ascending (the scan loop produces them i
( buf: Buffer, lineStart: number, candidates: number[], )
| 3273 | * first depth-1 hit. |
| 3274 | */ |
| 3275 | function pickDepthOneUuidCandidate( |
| 3276 | buf: Buffer, |
| 3277 | lineStart: number, |
| 3278 | candidates: number[], |
| 3279 | ): number { |
| 3280 | const QUOTE = 0x22 |
| 3281 | const BACKSLASH = 0x5c |
| 3282 | const OPEN_BRACE = 0x7b |
| 3283 | const CLOSE_BRACE = 0x7d |
| 3284 | let depth = 0 |
| 3285 | let inString = false |
| 3286 | let escapeNext = false |
| 3287 | let ci = 0 |
| 3288 | for (let i = lineStart; ci < candidates.length; i++) { |
| 3289 | if (i === candidates[ci]) { |
| 3290 | if (depth === 1 && !inString) return candidates[ci]! |
| 3291 | ci++ |
| 3292 | } |
| 3293 | const b = buf[i]! |
| 3294 | if (escapeNext) { |
| 3295 | escapeNext = false |
| 3296 | } else if (inString) { |
| 3297 | if (b === BACKSLASH) escapeNext = true |
| 3298 | else if (b === QUOTE) inString = false |
| 3299 | } else if (b === QUOTE) inString = true |
| 3300 | else if (b === OPEN_BRACE) depth++ |
| 3301 | else if (b === CLOSE_BRACE) depth-- |
| 3302 | } |
| 3303 | return candidates.at(-1)! |
| 3304 | } |
| 3305 | |
| 3306 | function walkChainBeforeParse(buf: Buffer): Buffer { |
| 3307 | const NEWLINE = 0x0a |
no outgoing calls
no test coverage detected