MCPcopy Create free account
hub / github.com/Noumena-Network/code / pickDepthOneUuidCandidate

Function pickDepthOneUuidCandidate

src/utils/sessionStorage.ts:3457–3486  ·  view source on GitHub ↗

* 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[],
)

Source from the content-addressed store, hash-verified

3455 * first depth-1 hit.
3456 */
3457function pickDepthOneUuidCandidate(
3458 buf: Buffer,
3459 lineStart: number,
3460 candidates: number[],
3461): number {
3462 const QUOTE = 0x22
3463 const BACKSLASH = 0x5c
3464 const OPEN_BRACE = 0x7b
3465 const CLOSE_BRACE = 0x7d
3466 let depth = 0
3467 let inString = false
3468 let escapeNext = false
3469 let ci = 0
3470 for (let i = lineStart; ci < candidates.length; i++) {
3471 if (i === candidates[ci]) {
3472 if (depth === 1 && !inString) return candidates[ci]!
3473 ci++
3474 }
3475 const b = buf[i]!
3476 if (escapeNext) {
3477 escapeNext = false
3478 } else if (inString) {
3479 if (b === BACKSLASH) escapeNext = true
3480 else if (b === QUOTE) inString = false
3481 } else if (b === QUOTE) inString = true
3482 else if (b === OPEN_BRACE) depth++
3483 else if (b === CLOSE_BRACE) depth--
3484 }
3485 return candidates.at(-1)!
3486}
3487
3488function walkChainBeforeParse(buf: Buffer): Buffer {
3489 const NEWLINE = 0x0a

Callers 1

walkChainBeforeParseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected