feat(RegExp): expose match indexes in Dart

This commit is contained in:
Victor Berchet 2015-02-26 16:31:56 +01:00
parent 009e11a6be
commit 06f7481141
2 changed files with 36 additions and 2 deletions

View File

@ -137,14 +137,24 @@ class RegExpWrapper {
}
class RegExpMatcherWrapper {
static Match next(Iterator<Match> matcher) {
static _JSLikeMatch next(Iterator<Match> matcher) {
if (matcher.moveNext()) {
return matcher.current;
return new _JSLikeMatch(matcher.current);
}
return null;
}
}
class _JSLikeMatch {
Match _m;
_JSLikeMatch(this._m);
String operator[](index) => _m[index];
int get index => _m.start;
int get length => _m.groupCount + 1;
}
class FunctionWrapper {
static apply(Function fn, posArgs) {
return Function.apply(fn, posArgs);

View File

@ -0,0 +1,24 @@
import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib';
import {ListWrapper} from 'angular2/src/facade/collection';
import {isPresent, RegExpWrapper, RegExpMatcherWrapper} from 'angular2/src/facade/lang';
export function main() {
describe('RegExp', () => {
it('should expose the index for each match', () => {
var re = RegExpWrapper.create('(!)');
var matcher = RegExpWrapper.matcher(re, '0!23!567!!');
var indexes = [];
var m;
while (isPresent(m = RegExpMatcherWrapper.next(matcher))) {
ListWrapper.push(indexes, m.index);
expect(m[0]).toEqual('!');
expect(m[1]).toEqual('!');
expect(m.length).toBe(2);
}
expect(indexes).toEqual([1, 4, 8, 9]);
})
});
}