src/LiveDevelopment/Agents/DOMHelpers.js
function _find(src, match, skip, quotes, comments) {
        if (typeof match === "string") {
            match = [match, match.length];
        }
        if (skip === undefined) {
            skip = 0;
        }
        var i, activeQuote, isComment = false;
        for (i = skip; i < src.length; i++) {
            if (quotes && _isQuote(src[i], src[i - 1], activeQuote)) {
                // starting quote
                activeQuote = activeQuote ? undefined : src[i];
            } else if (!activeQuote) {
                if (comments && !isComment && src.substr(i, comments[0].length) === comments[0]) {
                    // opening comment
                    isComment = true;
                    i += comments[0].length - 1;
                } else if (isComment) {
                    // we are commented
                    if (src.substr(i, comments[1].length) === comments[1]) {
                        isComment = false;
                        i += comments[1].length - 1;
                    }
                } else if (src.substr(i, match[1]).search(match[0]) === 0) {
                    // match
                    return i;
                }
            }
        }
        return -1;
    }
function _find(src, match, skip, quotes, comments) {
        if (typeof match === "string") {
            match = [match, match.length];
        }
        if (skip === undefined) {
            skip = 0;
        }
        var i, activeQuote, isComment = false;
        for (i = skip; i < src.length; i++) {
            if (quotes && _isQuote(src[i], src[i - 1], activeQuote)) {
                // starting quote
                activeQuote = activeQuote ? undefined : src[i];
            } else if (!activeQuote) {
                if (comments && !isComment && src.substr(i, comments[0].length) === comments[0]) {
                    // opening comment
                    isComment = true;
                    i += comments[0].length - 1;
                } else if (isComment) {
                    // we are commented
                    if (src.substr(i, comments[1].length) === comments[1]) {
                        isComment = false;
                        i += comments[1].length - 1;
                    }
                } else if (src.substr(i, match[1]).search(match[0]) === 0) {
                    // match
                    return i;
                }
            }
        }
        return -1;
    }
function _find ( src , match , skip , quotes , comments ) { if ( typeof match === "string" ) { match = [ match , match . length ] ; } if ( skip === undefined ) { skip = 0 ; } var i , activeQuote , isComment = false ; for ( i = skip ; i < src . length ; i ++ ) { if ( quotes && _isQuote ( src [ i ] , src [ i - 1 ] , activeQuote ) ) { // starting quote activeQuote = activeQuote ? undefined : src [ i ] ; } else if ( ! activeQuote ) { if ( comments && ! isComment && src . substr ( i , comments [ 0 ] . length ) === comments [ 0 ] ) { // opening comment isComment = true ; i += comments [ 0 ] . length - 1 ; } else if ( isComment ) { // we are commented if ( src . substr ( i , comments [ 1 ] . length ) === comments [ 1 ] ) { isComment = false ; i += comments [ 1 ] . length - 1 ; } } else if ( src . substr ( i , match [ 1 ] ) . search ( match [ 0 ] ) === 0 ) { // match return i ; } } } return - 1 ; }
Find the next match using several constraints
@param {string} source string
@param {string} or [{regex}, {length}] the match definition
@param {integer} ignore characters before this offset
@param {boolean} watch for quotes
@param [{string},{string}] watch for comments
Find the next match using several constraints