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

Function checkBalancedParentheses

Rewrite-Parser.js:2866–2883  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

2864 }
2865
2866 function checkBalancedParentheses(input) {
2867 let stack = []
2868 for (let i = 0; i < input.length; i++) {
2869 const char = input[i]
2870 if (char === '(') {
2871 stack.push(i)
2872 } else if (char === ')') {
2873 if (stack.length === 0) {
2874 return { balanced: false, position: i }
2875 }
2876 stack.pop()
2877 }
2878 }
2879 if (stack.length > 0) {
2880 return { balanced: false, position: stack.pop() }
2881 }
2882 return { balanced: true }
2883 }
2884 // console.log('=== 开始解析规则 ===')
2885 const balanceCheck = checkBalancedParentheses(input)
2886 if (!balanceCheck.balanced) {

Callers 1

parseRuleFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected