src/extensions/default/CodeFolding/foldhelpers/handlebarsFold.js
function scanTextUntil(cm, startCh, startLine, condition) {
        var line = cm.getLine(startLine),
            seen = "",
            characterIndex = startCh,
            currentLine = startLine,
            range;
        while (currentLine <= cm.lastLine()) {
            if (line.length === 0) {
                characterIndex = 0;
                line = cm.getLine(++currentLine);
            } else {
                seen = seen.concat(line[characterIndex] || "");
                if (condition(seen)) {
                    range = {
                        from: {ch: startCh, line: startLine},
                        to: {ch: characterIndex, line: currentLine},
                        string: seen
                    };
                    return range;
                } else if (characterIndex >= line.length) {
                    seen = seen.concat(cm.lineSeparator());
                    if (condition(seen)) {
                        range = {
                            from: {ch: startCh, line: startLine},
                            to: {ch: characterIndex, line: currentLine},
                            string: seen
                        };
                        return range;
                    }
                    characterIndex = 0;
                    line = cm.getLine(++currentLine);
                } else {
                    ++characterIndex;
                }
            }
        }
    }
function scanTextUntil(cm, startCh, startLine, condition) {
        var line = cm.getLine(startLine),
            seen = "",
            characterIndex = startCh,
            currentLine = startLine,
            range;
        while (currentLine <= cm.lastLine()) {
            if (line.length === 0) {
                characterIndex = 0;
                line = cm.getLine(++currentLine);
            } else {
                seen = seen.concat(line[characterIndex] || "");
                if (condition(seen)) {
                    range = {
                        from: {ch: startCh, line: startLine},
                        to: {ch: characterIndex, line: currentLine},
                        string: seen
                    };
                    return range;
                } else if (characterIndex >= line.length) {
                    seen = seen.concat(cm.lineSeparator());
                    if (condition(seen)) {
                        range = {
                            from: {ch: startCh, line: startLine},
                            to: {ch: characterIndex, line: currentLine},
                            string: seen
                        };
                        return range;
                    }
                    characterIndex = 0;
                    line = cm.getLine(++currentLine);
                } else {
                    ++characterIndex;
                }
            }
        }
    }
function scanTextUntil ( cm , startCh , startLine , condition ) { var line = cm . getLine ( startLine ) , seen = "" , characterIndex = startCh , currentLine = startLine , range ; while ( currentLine <= cm . lastLine ( ) ) { if ( line . length === 0 ) { characterIndex = 0 ; line = cm . getLine ( ++ currentLine ) ; } else { seen = seen . concat ( line [ characterIndex ] || "" ) ; if ( condition ( seen ) ) { range = { from : { ch : startCh , line : startLine } , to : { ch : characterIndex , line : currentLine } , string : seen } ; return range ; } else if ( characterIndex >= line . length ) { seen = seen . concat ( cm . lineSeparator ( ) ) ; if ( condition ( seen ) ) { range = { from : { ch : startCh , line : startLine } , to : { ch : characterIndex , line : currentLine } , string : seen } ; return range ; } characterIndex = 0 ; line = cm . getLine ( ++ currentLine ) ; } else { ++ characterIndex ; } } } }
Utility function for scanning the text in a document until a certain condition is met
@param {object}  cm  The code mirror object representing the document
@param {string}  startCh  The start character position for the scan operation
@param {number}  startLine The start line position for the scan operation
@param {function (string): boolean} condition A predicate function that takes in the text seen so far and returns true if the scanning process should be halted
@returns {{from:CodeMirror.Pos, to: CodeMirror.Pos, string: string}} An object representing the range of text scanned.
Utility function for scanning the text in a document until a certain condition is met