File: re2.js

package info (click to toggle)
node-re2 1.21.4%2B~cs2.13.13-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 964 kB
  • sloc: javascript: 5,558; cpp: 2,019; makefile: 14; sh: 9
file content (39 lines) | stat: -rw-r--r-- 855 bytes parent folder | download
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
38
39
'use strict';

const RE2 = require('./build/Release/re2.node');
// const RE2 = require('./build/Debug/re2.node');

const setAliases = (object, dict) => {
  for (let [name, alias] of Object.entries(dict)) {
    Object.defineProperty(
      object,
      alias,
      Object.getOwnPropertyDescriptor(object, name)
    );
  }
};

setAliases(RE2.prototype, {
  match: Symbol.match,
  search: Symbol.search,
  replace: Symbol.replace,
  split: Symbol.split
});

RE2.prototype[Symbol.matchAll] = function* (str) {
  if (!this.global)
    throw TypeError(
      'String.prototype.matchAll() is 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;
    if (result[0] === '') ++re.lastIndex;
    yield result;
  }
};

module.exports = RE2;