r112679 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112678‎ | r112679 | r112680 >
Date:10:49, 29 February 2012
Author:gwicke
Status:deferred
Tags:
Comment:
Support capturing regexps in dumpGrepper.
Modified paths:
  • /trunk/extensions/VisualEditor/tests/parser/dumpGrepper.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/tests/parser/dumpGrepper.js
@@ -19,10 +19,15 @@
2020 DumpGrepper.prototype.constructor = DumpGrepper;
2121
2222 DumpGrepper.prototype.grepRev = function ( revision ) {
23 - var bits = revision.text.split( this.re );
24 - if ( bits.length > 1 ) {
25 - this.emit( 'match', revision, bits );
 23+ var result = this.re.exec( revision.text ),
 24+ matches = [];
 25+ while ( result ) {
 26+ matches.push( result );
 27+ result = this.re.exec( revision.text );
2628 }
 29+ if ( matches.length ) {
 30+ this.emit( 'match', revision, matches );
 31+ }
2732 };
2833
2934 module.exports.DumpGrepper = DumpGrepper;
@@ -46,7 +51,7 @@
4752 process.exit( 0 );
4853 }
4954
50 - var flags = '';
 55+ var flags = 'g';
5156 if(argv.i) {
5257 flags += 'i';
5358 }
@@ -57,14 +62,21 @@
5863 grepper = new DumpGrepper( re );
5964
6065 reader.on( 'revision', grepper.grepRev.bind( grepper ) );
61 - grepper.on( 'match', function ( revision, bits ) {
62 - for ( var i = 0, l = bits.length; i < l-1; i += 2 ) {
 66+ grepper.on( 'match', function ( revision, matches ) {
 67+ for ( var i = 0, l = matches.length; i < l; i++ ) {
6368 console.log( '== Match: [[' + revision.page.title + ']] ==' );
64 - var m = bits[i+1];
 69+ var m = matches[i];
 70+ //console.warn( JSON.stringify( m.index, null, 2 ) );
6571 if ( argv.color ) {
66 - console.log( bits[i].substr(-40) + m.green + bits[i+2].substr( 0, 40 ) );
 72+ console.log(
 73+ revision.text.substr( m.index - 40, 40 ) +
 74+ m[0].green +
 75+ revision.text.substr( m.index + m[0].length, 40 ) );
6776 } else {
68 - console.log( bits[i].substr(-40) + m + bits[i+2].substr( 0, 40 ) );
 77+ console.log(
 78+ revision.text.substr( m.index, -40 ) +
 79+ m[0] +
 80+ revision.text.substr( m.index + m[0].length, 40 ) );
6981 }
7082 }
7183 } );

Status & tagging log