Index: trunk/extensions/VisualEditor/tests/parser/dumpGrepper.js |
— | — | @@ -19,10 +19,15 @@ |
20 | 20 | DumpGrepper.prototype.constructor = DumpGrepper; |
21 | 21 | |
22 | 22 | 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 ); |
26 | 28 | } |
| 29 | + if ( matches.length ) { |
| 30 | + this.emit( 'match', revision, matches ); |
| 31 | + } |
27 | 32 | }; |
28 | 33 | |
29 | 34 | module.exports.DumpGrepper = DumpGrepper; |
— | — | @@ -46,7 +51,7 @@ |
47 | 52 | process.exit( 0 ); |
48 | 53 | } |
49 | 54 | |
50 | | - var flags = ''; |
| 55 | + var flags = 'g'; |
51 | 56 | if(argv.i) { |
52 | 57 | flags += 'i'; |
53 | 58 | } |
— | — | @@ -57,14 +62,21 @@ |
58 | 63 | grepper = new DumpGrepper( re ); |
59 | 64 | |
60 | 65 | 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++ ) { |
63 | 68 | 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 ) ); |
65 | 71 | 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 ) ); |
67 | 76 | } 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 ) ); |
69 | 81 | } |
70 | 82 | } |
71 | 83 | } ); |