MCPcopy Create free account
hub / github.com/Script-Hub-Org/Script-Hub / checkBalancedParentheses

Function checkBalancedParentheses

Rewrite-Parser.beta.js:3278–3295  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

3276 }
3277
3278 function checkBalancedParentheses(input) {
3279 let stack = []
3280 for (let i = 0; i < input.length; i++) {
3281 const char = input[i]
3282 if (char === '(') {
3283 stack.push(i)
3284 } else if (char === ')') {
3285 if (stack.length === 0) {
3286 return { balanced: false, position: i }
3287 }
3288 stack.pop()
3289 }
3290 }
3291 if (stack.length > 0) {
3292 return { balanced: false, position: stack.pop() }
3293 }
3294 return { balanced: true }
3295 }
3296 // console.log('=== 开始解析规则 ===')
3297 const balanceCheck = checkBalancedParentheses(input)
3298 if (!balanceCheck.balanced) {

Callers 1

parseRuleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected