-
Notifications
You must be signed in to change notification settings - Fork 0
/
re2.js
37 lines (34 loc) · 980 Bytes
/
re2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const RE2 = require('./build/Release/re2');
if (typeof Symbol != 'undefined') {
Symbol.match &&
(RE2.prototype[Symbol.match] = function (str) {
return this.match(str);
});
Symbol.search &&
(RE2.prototype[Symbol.search] = function (str) {
return this.search(str);
});
Symbol.replace &&
(RE2.prototype[Symbol.replace] = function (str, repl) {
return this.replace(str, repl);
});
Symbol.split &&
(RE2.prototype[Symbol.split] = function (str, limit) {
return this.split(str, limit);
});
Symbol.matchAll &&
(RE2.prototype[Symbol.matchAll] = function* (str) {
if (!this.global) {
throw TypeError('String.prototype.matchAll called with a non-global RE2 argument');
}
const re = new RE2(this);
re.lastIndex = this.lastIndex;
for (;;) {
const result = re.exec(str);
if (!result) break;
yield result;
}
});
}
module.exports = RE2;