rregex 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +190 -1
- package/babel.config.js +7 -0
- package/jest.transform.js +3 -0
- package/lib/browser.d.ts +461 -23
- package/lib/browser.js +289 -82
- package/lib/commonjs.d.ts +440 -10
- package/lib/commonjs.js +297 -85
- package/lib/module.d.ts +440 -10
- package/lib/module.js +295 -84
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +21 -13
- package/lib/types.d.ts +461 -23
- package/package.json +13 -3
- package/test/rregex.test.ts +232 -0
package/lib/commonjs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let imports = {};
|
|
2
|
-
imports['
|
|
2
|
+
imports['wbg'] = module.exports;
|
|
3
3
|
let wasm;
|
|
4
4
|
const { TextDecoder, TextEncoder } = require(`util`);
|
|
5
5
|
|
|
@@ -48,6 +48,73 @@ function addHeapObject(obj) {
|
|
|
48
48
|
return idx;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
let WASM_VECTOR_LEN = 0;
|
|
52
|
+
|
|
53
|
+
let cachedTextEncoder = new TextEncoder('utf-8');
|
|
54
|
+
|
|
55
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
56
|
+
? function (arg, view) {
|
|
57
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
58
|
+
}
|
|
59
|
+
: function (arg, view) {
|
|
60
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
61
|
+
view.set(buf);
|
|
62
|
+
return {
|
|
63
|
+
read: arg.length,
|
|
64
|
+
written: buf.length
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
69
|
+
|
|
70
|
+
if (realloc === undefined) {
|
|
71
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
72
|
+
const ptr = malloc(buf.length);
|
|
73
|
+
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
74
|
+
WASM_VECTOR_LEN = buf.length;
|
|
75
|
+
return ptr;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let len = arg.length;
|
|
79
|
+
let ptr = malloc(len);
|
|
80
|
+
|
|
81
|
+
const mem = getUint8Memory0();
|
|
82
|
+
|
|
83
|
+
let offset = 0;
|
|
84
|
+
|
|
85
|
+
for (; offset < len; offset++) {
|
|
86
|
+
const code = arg.charCodeAt(offset);
|
|
87
|
+
if (code > 0x7F) break;
|
|
88
|
+
mem[ptr + offset] = code;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (offset !== len) {
|
|
92
|
+
if (offset !== 0) {
|
|
93
|
+
arg = arg.slice(offset);
|
|
94
|
+
}
|
|
95
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
|
96
|
+
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
97
|
+
const ret = encodeString(arg, view);
|
|
98
|
+
|
|
99
|
+
offset += ret.written;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
WASM_VECTOR_LEN = offset;
|
|
103
|
+
return ptr;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function isLikeNone(x) {
|
|
107
|
+
return x === undefined || x === null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let cachegetInt32Memory0 = null;
|
|
111
|
+
function getInt32Memory0() {
|
|
112
|
+
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
113
|
+
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
114
|
+
}
|
|
115
|
+
return cachegetInt32Memory0;
|
|
116
|
+
}
|
|
117
|
+
|
|
51
118
|
function debugString(val) {
|
|
52
119
|
// primitive types
|
|
53
120
|
const type = typeof val;
|
|
@@ -112,69 +179,25 @@ function debugString(val) {
|
|
|
112
179
|
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
113
180
|
return className;
|
|
114
181
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
134
|
-
|
|
135
|
-
if (realloc === undefined) {
|
|
136
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
137
|
-
const ptr = malloc(buf.length);
|
|
138
|
-
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
139
|
-
WASM_VECTOR_LEN = buf.length;
|
|
140
|
-
return ptr;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
let len = arg.length;
|
|
144
|
-
let ptr = malloc(len);
|
|
145
|
-
|
|
146
|
-
const mem = getUint8Memory0();
|
|
147
|
-
|
|
148
|
-
let offset = 0;
|
|
149
|
-
|
|
150
|
-
for (; offset < len; offset++) {
|
|
151
|
-
const code = arg.charCodeAt(offset);
|
|
152
|
-
if (code > 0x7F) break;
|
|
153
|
-
mem[ptr + offset] = code;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (offset !== len) {
|
|
157
|
-
if (offset !== 0) {
|
|
158
|
-
arg = arg.slice(offset);
|
|
159
|
-
}
|
|
160
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
|
161
|
-
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
162
|
-
const ret = encodeString(arg, view);
|
|
163
|
-
|
|
164
|
-
offset += ret.written;
|
|
182
|
+
/**
|
|
183
|
+
* @param {string} text
|
|
184
|
+
* @returns {string}
|
|
185
|
+
*/
|
|
186
|
+
module.exports.escape = function(text) {
|
|
187
|
+
try {
|
|
188
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
189
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
190
|
+
var len0 = WASM_VECTOR_LEN;
|
|
191
|
+
wasm.escape(retptr, ptr0, len0);
|
|
192
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
193
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
194
|
+
return getStringFromWasm0(r0, r1);
|
|
195
|
+
} finally {
|
|
196
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
197
|
+
wasm.__wbindgen_free(r0, r1);
|
|
165
198
|
}
|
|
199
|
+
};
|
|
166
200
|
|
|
167
|
-
WASM_VECTOR_LEN = offset;
|
|
168
|
-
return ptr;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
let cachegetInt32Memory0 = null;
|
|
172
|
-
function getInt32Memory0() {
|
|
173
|
-
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
174
|
-
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
175
|
-
}
|
|
176
|
-
return cachegetInt32Memory0;
|
|
177
|
-
}
|
|
178
201
|
/**
|
|
179
202
|
* @returns {any}
|
|
180
203
|
*/
|
|
@@ -183,6 +206,14 @@ module.exports.get_metadata = function() {
|
|
|
183
206
|
return takeObject(ret);
|
|
184
207
|
};
|
|
185
208
|
|
|
209
|
+
let stack_pointer = 32;
|
|
210
|
+
|
|
211
|
+
function addBorrowedObject(obj) {
|
|
212
|
+
if (stack_pointer == 1) throw new Error('out of js stack');
|
|
213
|
+
heap[--stack_pointer] = obj;
|
|
214
|
+
return stack_pointer;
|
|
215
|
+
}
|
|
216
|
+
|
|
186
217
|
function handleError(f, args) {
|
|
187
218
|
try {
|
|
188
219
|
return f.apply(this, args);
|
|
@@ -191,11 +222,13 @@ function handleError(f, args) {
|
|
|
191
222
|
}
|
|
192
223
|
}
|
|
193
224
|
/**
|
|
225
|
+
* A compiled regular expression for matching Unicode strings.
|
|
226
|
+
* @see https://docs.rs/regex/latest/regex/
|
|
194
227
|
*/
|
|
195
|
-
class
|
|
228
|
+
class RRegex {
|
|
196
229
|
|
|
197
230
|
static __wrap(ptr) {
|
|
198
|
-
const obj = Object.create(
|
|
231
|
+
const obj = Object.create(RRegex.prototype);
|
|
199
232
|
obj.ptr = ptr;
|
|
200
233
|
|
|
201
234
|
return obj;
|
|
@@ -210,70 +243,90 @@ class RRegExp {
|
|
|
210
243
|
|
|
211
244
|
free() {
|
|
212
245
|
const ptr = this.__destroy_into_raw();
|
|
213
|
-
wasm.
|
|
246
|
+
wasm.__wbg_rregex_free(ptr);
|
|
214
247
|
}
|
|
215
248
|
/**
|
|
249
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly to search, split or replace text in a string.
|
|
250
|
+
* If an invalid expression is given, then an error is returned.
|
|
216
251
|
* @param {string} re
|
|
217
252
|
*/
|
|
218
253
|
constructor(re) {
|
|
219
254
|
var ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
220
255
|
var len0 = WASM_VECTOR_LEN;
|
|
221
|
-
var ret = wasm.
|
|
222
|
-
return
|
|
256
|
+
var ret = wasm.rregex_new(ptr0, len0);
|
|
257
|
+
return RRegex.__wrap(ret);
|
|
223
258
|
}
|
|
224
259
|
/**
|
|
260
|
+
* Returns true if and only if there is a match for the regex in the string given.
|
|
261
|
+
* It is recommended to use this method if all you need to do is test a match, since the underlying matching engine may be able to do less work.
|
|
262
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
225
263
|
* @param {string} text
|
|
226
264
|
* @returns {boolean}
|
|
227
265
|
*/
|
|
228
|
-
|
|
266
|
+
isMatch(text) {
|
|
229
267
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
230
268
|
var len0 = WASM_VECTOR_LEN;
|
|
231
|
-
var ret = wasm.
|
|
269
|
+
var ret = wasm.rregex_isMatch(this.ptr, ptr0, len0);
|
|
232
270
|
return ret !== 0;
|
|
233
271
|
}
|
|
234
272
|
/**
|
|
273
|
+
* Returns the same as is_match, but starts the search at the given offset.
|
|
274
|
+
* The significance of the starting point is that it takes the surrounding context into consideration. For example, the `\A` anchor can only match when `start == 0`.
|
|
275
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
235
276
|
* @param {string} text
|
|
236
277
|
* @param {number} start
|
|
237
278
|
* @returns {boolean}
|
|
238
279
|
*/
|
|
239
|
-
|
|
280
|
+
isMatchAt(text, start) {
|
|
240
281
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
241
282
|
var len0 = WASM_VECTOR_LEN;
|
|
242
|
-
var ret = wasm.
|
|
283
|
+
var ret = wasm.rregex_isMatchAt(this.ptr, ptr0, len0, start);
|
|
243
284
|
return ret !== 0;
|
|
244
285
|
}
|
|
245
286
|
/**
|
|
287
|
+
* Returns the start and end byte range of the leftmost-first match in `text`. If no match exists, then `undefined` is returned.
|
|
288
|
+
* Note that this should only be used if you want to discover the position of the match. Testing the existence of a match is faster if you use `is_match`.
|
|
289
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
246
290
|
* @param {string} text
|
|
247
291
|
* @returns {any}
|
|
248
292
|
*/
|
|
249
293
|
find(text) {
|
|
250
294
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
251
295
|
var len0 = WASM_VECTOR_LEN;
|
|
252
|
-
var ret = wasm.
|
|
296
|
+
var ret = wasm.rregex_find(this.ptr, ptr0, len0);
|
|
253
297
|
return takeObject(ret);
|
|
254
298
|
}
|
|
255
299
|
/**
|
|
300
|
+
* Returns the same as find, but starts the search at the given offset.
|
|
301
|
+
* The significance of the starting point is that it takes the surrounding context into consideration. For example, the \A anchor can only match when `start == 0`.
|
|
302
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
256
303
|
* @param {string} text
|
|
257
304
|
* @param {number} start
|
|
258
305
|
* @returns {any}
|
|
259
306
|
*/
|
|
260
|
-
|
|
307
|
+
findAt(text, start) {
|
|
261
308
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
262
309
|
var len0 = WASM_VECTOR_LEN;
|
|
263
|
-
var ret = wasm.
|
|
310
|
+
var ret = wasm.rregex_findAt(this.ptr, ptr0, len0, start);
|
|
264
311
|
return takeObject(ret);
|
|
265
312
|
}
|
|
266
313
|
/**
|
|
314
|
+
* Returns an array for each successive non-overlapping match in text, returning the start and end byte indices with respect to text.
|
|
315
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
267
316
|
* @param {string} text
|
|
268
317
|
* @returns {any}
|
|
269
318
|
*/
|
|
270
|
-
|
|
319
|
+
findAll(text) {
|
|
271
320
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
272
321
|
var len0 = WASM_VECTOR_LEN;
|
|
273
|
-
var ret = wasm.
|
|
322
|
+
var ret = wasm.rregex_findAll(this.ptr, ptr0, len0);
|
|
274
323
|
return takeObject(ret);
|
|
275
324
|
}
|
|
276
325
|
/**
|
|
326
|
+
* Replaces the leftmost-first match with the replacement provided.
|
|
327
|
+
* The replacement can be a regular string (where `$N` and `$name` are expanded to match capture groups) or a function that takes the matches’ `Captures` and returns the replaced string.
|
|
328
|
+
* If no match is found, then a copy of the string is returned unchanged.
|
|
329
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
277
330
|
* @param {string} text
|
|
278
331
|
* @param {string} rep
|
|
279
332
|
* @returns {string}
|
|
@@ -285,7 +338,7 @@ class RRegExp {
|
|
|
285
338
|
var len0 = WASM_VECTOR_LEN;
|
|
286
339
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
287
340
|
var len1 = WASM_VECTOR_LEN;
|
|
288
|
-
wasm.
|
|
341
|
+
wasm.rregex_replace(retptr, this.ptr, ptr0, len0, ptr1, len1);
|
|
289
342
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
290
343
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
291
344
|
return getStringFromWasm0(r0, r1);
|
|
@@ -295,6 +348,9 @@ class RRegExp {
|
|
|
295
348
|
}
|
|
296
349
|
}
|
|
297
350
|
/**
|
|
351
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the replacement provided. If `limit` is 0, then all non-overlapping matches are replaced.
|
|
352
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
353
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
298
354
|
* @param {string} text
|
|
299
355
|
* @param {number} limit
|
|
300
356
|
* @param {string} rep
|
|
@@ -307,7 +363,7 @@ class RRegExp {
|
|
|
307
363
|
var len0 = WASM_VECTOR_LEN;
|
|
308
364
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
309
365
|
var len1 = WASM_VECTOR_LEN;
|
|
310
|
-
wasm.
|
|
366
|
+
wasm.rregex_replacen(retptr, this.ptr, ptr0, len0, limit, ptr1, len1);
|
|
311
367
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
312
368
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
313
369
|
return getStringFromWasm0(r0, r1);
|
|
@@ -317,18 +373,21 @@ class RRegExp {
|
|
|
317
373
|
}
|
|
318
374
|
}
|
|
319
375
|
/**
|
|
376
|
+
* Replaces all non-overlapping matches in `text` with the replacement provided. This is the same as calling `replacen` with `limit` set to `0`.
|
|
377
|
+
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
378
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
320
379
|
* @param {string} text
|
|
321
380
|
* @param {string} rep
|
|
322
381
|
* @returns {string}
|
|
323
382
|
*/
|
|
324
|
-
|
|
383
|
+
replaceAll(text, rep) {
|
|
325
384
|
try {
|
|
326
385
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
327
386
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
328
387
|
var len0 = WASM_VECTOR_LEN;
|
|
329
388
|
var ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
330
389
|
var len1 = WASM_VECTOR_LEN;
|
|
331
|
-
wasm.
|
|
390
|
+
wasm.rregex_replaceAll(retptr, this.ptr, ptr0, len0, ptr1, len1);
|
|
332
391
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
333
392
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
334
393
|
return getStringFromWasm0(r0, r1);
|
|
@@ -338,16 +397,22 @@ class RRegExp {
|
|
|
338
397
|
}
|
|
339
398
|
}
|
|
340
399
|
/**
|
|
400
|
+
* Returns an iterator of substrings of `text` delimited by a match of the regular expression. Namely, each element of the iterator corresponds to text that isn’t matched by the regular expression.
|
|
401
|
+
* This method will not copy the text given.
|
|
402
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
341
403
|
* @param {string} text
|
|
342
404
|
* @returns {any}
|
|
343
405
|
*/
|
|
344
406
|
split(text) {
|
|
345
407
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
346
408
|
var len0 = WASM_VECTOR_LEN;
|
|
347
|
-
var ret = wasm.
|
|
409
|
+
var ret = wasm.rregex_split(this.ptr, ptr0, len0);
|
|
348
410
|
return takeObject(ret);
|
|
349
411
|
}
|
|
350
412
|
/**
|
|
413
|
+
* Returns an iterator of at most `limit` substrings of `text` delimited by a match of the regular expression. (A limit of 0 will return no substrings.) Namely, each element of the iterator corresponds to text that isn’t matched by the regular expression. The remainder of the string that is not split will be the last element in the iterator.
|
|
414
|
+
* This method will not copy the text given.
|
|
415
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
351
416
|
* @param {string} text
|
|
352
417
|
* @param {number} limit
|
|
353
418
|
* @returns {any}
|
|
@@ -355,18 +420,141 @@ class RRegExp {
|
|
|
355
420
|
splitn(text, limit) {
|
|
356
421
|
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
357
422
|
var len0 = WASM_VECTOR_LEN;
|
|
358
|
-
var ret = wasm.
|
|
423
|
+
var ret = wasm.rregex_splitn(this.ptr, ptr0, len0, limit);
|
|
359
424
|
return takeObject(ret);
|
|
360
425
|
}
|
|
361
426
|
/**
|
|
427
|
+
* Returns the end location of a match in the text given.
|
|
428
|
+
* This method may have the same performance characteristics as `is_match`, except it provides an end location for a match. In particular, the location returned may be shorter than the proper end of the leftmost-first match.
|
|
429
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
430
|
+
* @param {string} text
|
|
431
|
+
* @returns {number | undefined}
|
|
432
|
+
*/
|
|
433
|
+
shortestMatch(text) {
|
|
434
|
+
try {
|
|
435
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
436
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
437
|
+
var len0 = WASM_VECTOR_LEN;
|
|
438
|
+
wasm.rregex_shortestMatch(retptr, this.ptr, ptr0, len0);
|
|
439
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
440
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
441
|
+
return r0 === 0 ? undefined : r1 >>> 0;
|
|
442
|
+
} finally {
|
|
443
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Returns the same as shortest_match, but starts the search at the given offset.
|
|
448
|
+
* The significance of the starting point is that it takes the surrounding context into consideration. For example, the \A anchor can only match when `start == 0`.
|
|
449
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
450
|
+
* @param {string} text
|
|
451
|
+
* @param {number} limit
|
|
452
|
+
* @returns {number | undefined}
|
|
453
|
+
*/
|
|
454
|
+
shortestMatchAt(text, limit) {
|
|
455
|
+
try {
|
|
456
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
457
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
458
|
+
var len0 = WASM_VECTOR_LEN;
|
|
459
|
+
wasm.rregex_shortestMatchAt(retptr, this.ptr, ptr0, len0, limit);
|
|
460
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
461
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
462
|
+
return r0 === 0 ? undefined : r1 >>> 0;
|
|
463
|
+
} finally {
|
|
464
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Return the Regex syntax object
|
|
362
469
|
* @returns {any}
|
|
363
470
|
*/
|
|
364
471
|
syntax() {
|
|
365
|
-
var ret = wasm.
|
|
472
|
+
var ret = wasm.rregex_syntax(this.ptr);
|
|
366
473
|
return takeObject(ret);
|
|
367
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* Returns a string representing the regular expression
|
|
477
|
+
* @returns {string}
|
|
478
|
+
*/
|
|
479
|
+
toString() {
|
|
480
|
+
try {
|
|
481
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
482
|
+
wasm.rregex_toString(retptr, this.ptr);
|
|
483
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
484
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
485
|
+
return getStringFromWasm0(r0, r1);
|
|
486
|
+
} finally {
|
|
487
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
488
|
+
wasm.__wbindgen_free(r0, r1);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
368
491
|
}
|
|
369
|
-
module.exports.
|
|
492
|
+
module.exports.RRegex = RRegex;
|
|
493
|
+
/**
|
|
494
|
+
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
495
|
+
* A regex set corresponds to the union of two or more regular expressions. That is, a regex set will match text where at least one of its constituent regular expressions matches. A regex set as its formulated here provides a touch more power: it will also report which regular expressions in the set match. Indeed, this is the key difference between regex sets and a single `Regex` with many alternates, since only one alternate can match at a time.
|
|
496
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
497
|
+
*/
|
|
498
|
+
class RRegexSet {
|
|
499
|
+
|
|
500
|
+
static __wrap(ptr) {
|
|
501
|
+
const obj = Object.create(RRegexSet.prototype);
|
|
502
|
+
obj.ptr = ptr;
|
|
503
|
+
|
|
504
|
+
return obj;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
__destroy_into_raw() {
|
|
508
|
+
const ptr = this.ptr;
|
|
509
|
+
this.ptr = 0;
|
|
510
|
+
|
|
511
|
+
return ptr;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
free() {
|
|
515
|
+
const ptr = this.__destroy_into_raw();
|
|
516
|
+
wasm.__wbg_rregexset_free(ptr);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Create a new regex set with the given regular expressions.
|
|
520
|
+
* @param {Array<any>} list
|
|
521
|
+
*/
|
|
522
|
+
constructor(list) {
|
|
523
|
+
try {
|
|
524
|
+
var ret = wasm.rregexset_new(addBorrowedObject(list));
|
|
525
|
+
return RRegexSet.__wrap(ret);
|
|
526
|
+
} finally {
|
|
527
|
+
heap[stack_pointer++] = undefined;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Returns true if and only if one of the regexes in this set matches the text given.
|
|
532
|
+
* This method should be preferred if you only need to test whether any of the regexes in the set should match, but don’t care about which regexes matched. This is because the underlying matching engine will quit immediately after seeing the first match instead of continuing to find all matches.
|
|
533
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
534
|
+
* @param {string} text
|
|
535
|
+
* @returns {boolean}
|
|
536
|
+
*/
|
|
537
|
+
isMatch(text) {
|
|
538
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
539
|
+
var len0 = WASM_VECTOR_LEN;
|
|
540
|
+
var ret = wasm.rregexset_isMatch(this.ptr, ptr0, len0);
|
|
541
|
+
return ret !== 0;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Returns the set of regular expressions that match in the given text.
|
|
545
|
+
* The set returned contains the index of each regular expression that matches in the given text. The index is in correspondence with the order of regular expressions given to RegexSet’s constructor.
|
|
546
|
+
* the set can also be used to iterate over the matched indices.
|
|
547
|
+
* @param {string} text
|
|
548
|
+
* @returns {any}
|
|
549
|
+
*/
|
|
550
|
+
matches(text) {
|
|
551
|
+
var ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
552
|
+
var len0 = WASM_VECTOR_LEN;
|
|
553
|
+
var ret = wasm.rregexset_matches(this.ptr, ptr0, len0);
|
|
554
|
+
return takeObject(ret);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
module.exports.RRegexSet = RRegexSet;
|
|
370
558
|
|
|
371
559
|
module.exports.__wbindgen_object_drop_ref = function(arg0) {
|
|
372
560
|
takeObject(arg0);
|
|
@@ -382,6 +570,30 @@ module.exports.__wbindgen_number_new = function(arg0) {
|
|
|
382
570
|
return addHeapObject(ret);
|
|
383
571
|
};
|
|
384
572
|
|
|
573
|
+
module.exports.__wbindgen_is_string = function(arg0) {
|
|
574
|
+
var ret = typeof(getObject(arg0)) === 'string';
|
|
575
|
+
return ret;
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
module.exports.__wbindgen_string_get = function(arg0, arg1) {
|
|
579
|
+
const obj = getObject(arg1);
|
|
580
|
+
var ret = typeof(obj) === 'string' ? obj : undefined;
|
|
581
|
+
var ptr0 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
582
|
+
var len0 = WASM_VECTOR_LEN;
|
|
583
|
+
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
|
584
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
module.exports.__wbg_get_67189fe0b323d288 = function(arg0, arg1) {
|
|
588
|
+
var ret = getObject(arg0)[arg1 >>> 0];
|
|
589
|
+
return addHeapObject(ret);
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
module.exports.__wbg_length_42e02f5a04d67464 = function(arg0) {
|
|
593
|
+
var ret = getObject(arg0).length;
|
|
594
|
+
return ret;
|
|
595
|
+
};
|
|
596
|
+
|
|
385
597
|
module.exports.__wbg_new_949bbc1147195c4e = function() {
|
|
386
598
|
var ret = new Array();
|
|
387
599
|
return addHeapObject(ret);
|
|
@@ -423,7 +635,7 @@ module.exports.__wbindgen_rethrow = function(arg0) {
|
|
|
423
635
|
throw takeObject(arg0);
|
|
424
636
|
};
|
|
425
637
|
|
|
426
|
-
const path = require('path').join(__dirname, '
|
|
638
|
+
const path = require('path').join(__dirname, 'rregex.wasm');
|
|
427
639
|
const bytes = require('fs').readFileSync(path);
|
|
428
640
|
|
|
429
641
|
const wasmModule = new WebAssembly.Module(bytes);
|