javascript/jssearch/src/searcher.js
// return results so that filepath can be added to them
return results so that filepath can be added to them
return results so that filepath can be added to them
async searchLines(lines) {
        let linenum = 0;
        let pattern;
        let linesBefore = [];
        let linesAfter = [];
        let results = [];
        let patternResults = {};
        while (true) {
            if (Object.keys(patternResults).length === this.settings.searchPatterns.length) {
                break;
            }
            let line = "";
            if (linesAfter.length > 0) {
                line = linesAfter.shift();
            } else if (lines.length > 0) {
                line = lines.shift();
            } else {
                break;
            }
            linenum += 1;
            if (this.settings.linesAfter > 0) {
                while (linesAfter.length < this.settings.linesAfter && lines.length > 0) {
                    linesAfter.push(lines.shift());
                }
            }
            this.settings.searchPatterns.forEach(p => {
                pattern = new RegExp(p.source, "g");
                let match = pattern.exec(line);
                while (match) {
                    if ((this.settings.linesBefore === 0 || this.linesBeforeMatch(linesBefore)) &&
                        (this.settings.linesAfter === 0 || this.linesAfterMatch(linesAfter))) {
                        results.push(new SearchResult(
                            pattern,
                            '',
                            linenum,
                            match.index+1,
                            pattern.lastIndex+1,
                            line,
                            [].concat(linesBefore),
                            [].concat(linesAfter),
                            this.settings.maxLineLength,
                            this.settings.colorize));
                        if (this.settings.firstMatch) {
                            patternResults[pattern.source] = 1;
                            break;
                        }
                    }
                    match = pattern.exec(line);
                }
            });
            if (this.settings.linesBefore > 0) {
                if (linesBefore.length === this.settings.linesBefore)
                    linesBefore.shift();
                if (linesBefore.length < this.settings.linesBefore)
                    linesBefore.push(line);
            }
        }
        return results;
    }
async searchLines ( lines ) { let linenum = 0 ; let pattern ; let linesBefore = [ ] ; let linesAfter = [ ] ; let results = [ ] ; let patternResults = { } ; while ( true ) { if ( Object . keys ( patternResults ) . length === this . settings . searchPatterns . length ) { break ; } let line = "" ; if ( linesAfter . length > 0 ) { line = linesAfter . shift ( ) ; } else if ( lines . length > 0 ) { line = lines . shift ( ) ; } else { break ; } linenum += 1 ; if ( this . settings . linesAfter > 0 ) { while ( linesAfter . length < this . settings . linesAfter && lines . length > 0 ) { linesAfter . push ( lines . shift ( ) ) ; } } this . settings . searchPatterns . forEach ( p => { pattern = new RegExp ( p . source , "g" ) ; let match = pattern . exec ( line ) ; while ( match ) { if ( ( this . settings . linesBefore === 0 || this . linesBeforeMatch ( linesBefore ) ) && ( this . settings . linesAfter === 0 || this . linesAfterMatch ( linesAfter ) ) ) { results . push ( new SearchResult ( pattern , '' , linenum , match . index + 1 , pattern . lastIndex + 1 , line , [ ] . concat ( linesBefore ) , [ ] . concat ( linesAfter ) , this . settings . maxLineLength , this . settings . colorize ) ) ; if ( this . settings . firstMatch ) { patternResults [ pattern . source ] = 1 ; break ; } } match = pattern . exec ( line ) ; } } ) ; if ( this . settings . linesBefore > 0 ) { if ( linesBefore . length === this . settings . linesBefore ) linesBefore . shift ( ) ; if ( linesBefore . length < this . settings . linesBefore ) linesBefore . push ( line ) ; } } return results ; }
return results so that filepath can be added to them
return results so that filepath can be added to them