MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / scan

Function scan

static/js/codemirror/addon/edit/matchbrackets.js:18–31  ·  view source on GitHub ↗
(line, lineNo, start)

Source from the content-addressed store, hash-verified

16
17 var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
18 function scan(line, lineNo, start) {
19 if (!line.text) return;
20 var pos = forward ? 0 : line.text.length - 1, end = forward ? line.text.length : -1;
21 if (start != null) pos = start + d;
22 for (; pos != end; pos += d) {
23 var ch = line.text.charAt(pos);
24 if (re.test(ch) && cm.getTokenAt(Pos(lineNo, pos + 1)).type == style) {
25 var match = matching[ch];
26 if (match.charAt(1) == ">" == forward) stack.push(ch);
27 else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
28 else if (!stack.length) return {pos: pos, match: true};
29 }
30 }
31 }
32 for (var i = cur.line, found, e = forward ? Math.min(i + 100, cm.lineCount()) : Math.max(-1, i - 100); i != e; i+=d) {
33 if (i == cur.line) found = scan(line, i, pos);
34 else found = scan(cm.getLineHandle(i), i);

Callers 1

findMatchingBracketFunction · 0.85

Calls 4

PosFunction · 0.85
testMethod · 0.45
pushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected