MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / bracketBalance

Function bracketBalance

scripts/rubi/extract-rules.ts:69–82  ·  view source on GitHub ↗

Net bracket depth of a fragment, ignoring brackets inside strings.

(s: string)

Source from the content-addressed store, hash-verified

67
68/** Net bracket depth of a fragment, ignoring brackets inside strings. */
69function bracketBalance(s: string): number {
70 let depth = 0;
71 let inString = false;
72 for (let i = 0; i < s.length; i++) {
73 const c = s[i];
74 if (inString) {
75 if (c === '\\') i++;
76 else if (c === '"') inString = false;
77 } else if (c === '"') inString = true;
78 else if ('[({'.includes(c)) depth++;
79 else if ('])}'.includes(c)) depth--;
80 }
81 return depth;
82}
83
84export function extractRules(filePath: string): ExtractResult {
85 const src = stripComments(readFileSync(filePath, 'utf8'));

Callers 1

extractRulesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected