rregex 1.7.1 → 1.9.0
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 +154 -47
- package/lib/browser.d.ts +790 -278
- package/lib/browser.js +649 -179
- package/lib/commonjs.d.ts +779 -271
- package/lib/commonjs.js +659 -182
- package/lib/module.d.ts +779 -271
- package/lib/module.js +656 -179
- package/lib/rregex.wasm +0 -0
- package/lib/rregex.wasm.d.ts +15 -11
- package/lib/types.d.ts +790 -278
- package/package.json +23 -2
package/lib/browser.js
CHANGED
|
@@ -4,10 +4,19 @@ const heap = new Array(128).fill(undefined);
|
|
|
4
4
|
|
|
5
5
|
heap.push(undefined, null, true, false);
|
|
6
6
|
|
|
7
|
-
function getObject(idx) { return heap[idx]; }
|
|
8
|
-
|
|
9
7
|
let heap_next = heap.length;
|
|
10
8
|
|
|
9
|
+
function addHeapObject(obj) {
|
|
10
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
11
|
+
const idx = heap_next;
|
|
12
|
+
heap_next = heap[idx];
|
|
13
|
+
|
|
14
|
+
heap[idx] = obj;
|
|
15
|
+
return idx;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getObject(idx) { return heap[idx]; }
|
|
19
|
+
|
|
11
20
|
function dropObject(idx) {
|
|
12
21
|
if (idx < 132) return;
|
|
13
22
|
heap[idx] = heap_next;
|
|
@@ -38,15 +47,6 @@ function getStringFromWasm0(ptr, len) {
|
|
|
38
47
|
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
function addHeapObject(obj) {
|
|
42
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
43
|
-
const idx = heap_next;
|
|
44
|
-
heap_next = heap[idx];
|
|
45
|
-
|
|
46
|
-
heap[idx] = obj;
|
|
47
|
-
return idx;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
50
|
let WASM_VECTOR_LEN = 0;
|
|
51
51
|
|
|
52
52
|
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
@@ -115,69 +115,24 @@ function getInt32Memory0() {
|
|
|
115
115
|
return cachedInt32Memory0;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
if (type == 'string') {
|
|
125
|
-
return `"${val}"`;
|
|
126
|
-
}
|
|
127
|
-
if (type == 'symbol') {
|
|
128
|
-
const description = val.description;
|
|
129
|
-
if (description == null) {
|
|
130
|
-
return 'Symbol';
|
|
131
|
-
} else {
|
|
132
|
-
return `Symbol(${description})`;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (type == 'function') {
|
|
136
|
-
const name = val.name;
|
|
137
|
-
if (typeof name == 'string' && name.length > 0) {
|
|
138
|
-
return `Function(${name})`;
|
|
139
|
-
} else {
|
|
140
|
-
return 'Function';
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// objects
|
|
144
|
-
if (Array.isArray(val)) {
|
|
145
|
-
const length = val.length;
|
|
146
|
-
let debug = '[';
|
|
147
|
-
if (length > 0) {
|
|
148
|
-
debug += debugString(val[0]);
|
|
149
|
-
}
|
|
150
|
-
for(let i = 1; i < length; i++) {
|
|
151
|
-
debug += ', ' + debugString(val[i]);
|
|
152
|
-
}
|
|
153
|
-
debug += ']';
|
|
154
|
-
return debug;
|
|
155
|
-
}
|
|
156
|
-
// Test for built-in
|
|
157
|
-
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
158
|
-
let className;
|
|
159
|
-
if (builtInMatches.length > 1) {
|
|
160
|
-
className = builtInMatches[1];
|
|
161
|
-
} else {
|
|
162
|
-
// Failed to match the standard '[object ClassName]'
|
|
163
|
-
return toString.call(val);
|
|
164
|
-
}
|
|
165
|
-
if (className == 'Object') {
|
|
166
|
-
// we're a user defined class or Object
|
|
167
|
-
// JSON.stringify avoids problems with cycles, and is generally much
|
|
168
|
-
// easier than looping through ownProperties of `val`.
|
|
169
|
-
try {
|
|
170
|
-
return 'Object(' + JSON.stringify(val) + ')';
|
|
171
|
-
} catch (_) {
|
|
172
|
-
return 'Object';
|
|
173
|
-
}
|
|
118
|
+
let cachedUint32Memory0 = null;
|
|
119
|
+
|
|
120
|
+
function getUint32Memory0() {
|
|
121
|
+
if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
|
|
122
|
+
cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
|
|
174
123
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
124
|
+
return cachedUint32Memory0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
128
|
+
ptr = ptr >>> 0;
|
|
129
|
+
const mem = getUint32Memory0();
|
|
130
|
+
const slice = mem.subarray(ptr / 4, ptr / 4 + len);
|
|
131
|
+
const result = [];
|
|
132
|
+
for (let i = 0; i < slice.length; i++) {
|
|
133
|
+
result.push(takeObject(slice[i]));
|
|
178
134
|
}
|
|
179
|
-
|
|
180
|
-
return className;
|
|
135
|
+
return result;
|
|
181
136
|
}
|
|
182
137
|
|
|
183
138
|
let stack_pointer = 128;
|
|
@@ -188,6 +143,10 @@ function addBorrowedObject(obj) {
|
|
|
188
143
|
return stack_pointer;
|
|
189
144
|
}
|
|
190
145
|
/**
|
|
146
|
+
* Escapes all regular expression meta characters in `text`.
|
|
147
|
+
*
|
|
148
|
+
* The string returned may be safely used as a literal in a regular
|
|
149
|
+
* expression.
|
|
191
150
|
* @param {string} text
|
|
192
151
|
* @returns {string}
|
|
193
152
|
*/
|
|
@@ -235,7 +194,9 @@ export class RRegex {
|
|
|
235
194
|
wasm.__wbg_rregex_free(ptr);
|
|
236
195
|
}
|
|
237
196
|
/**
|
|
238
|
-
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
197
|
+
* Compiles a regular expression. Once compiled, it can be used repeatedly
|
|
198
|
+
* to search, split or replace text in a string.
|
|
199
|
+
*
|
|
239
200
|
* If an invalid expression is given, then an error is returned.
|
|
240
201
|
* @param {string} re
|
|
241
202
|
*/
|
|
@@ -258,11 +219,26 @@ export class RRegex {
|
|
|
258
219
|
}
|
|
259
220
|
}
|
|
260
221
|
/**
|
|
261
|
-
* Returns true if and only if there is a match for the regex in the
|
|
262
|
-
*
|
|
222
|
+
* Returns true if and only if there is a match for the regex in the
|
|
223
|
+
* string given.
|
|
224
|
+
*
|
|
225
|
+
* It is recommended to use this method if all you need to do is test
|
|
226
|
+
* a match, since the underlying matching engine may be able to do less
|
|
227
|
+
* work.
|
|
228
|
+
*
|
|
229
|
+
* # Example
|
|
230
|
+
*
|
|
231
|
+
* Test if some text contains at least one word with exactly 13
|
|
232
|
+
* Unicode word characters:
|
|
233
|
+
*
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
236
|
+
* expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
263
239
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
|
|
264
|
-
* @param {string} text
|
|
265
|
-
* @
|
|
240
|
+
* @param {string} text - The string against which to match the regular expression
|
|
241
|
+
* @return {boolean}
|
|
266
242
|
*/
|
|
267
243
|
isMatch(text) {
|
|
268
244
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -272,11 +248,14 @@ export class RRegex {
|
|
|
272
248
|
}
|
|
273
249
|
/**
|
|
274
250
|
* Returns the same as is_match, but starts the search at the given offset.
|
|
275
|
-
* The significance of the starting point is that it takes the surrounding
|
|
251
|
+
* The significance of the starting point is that it takes the surrounding
|
|
252
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
253
|
+
* when `start == 0`.
|
|
254
|
+
*
|
|
276
255
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
|
|
277
|
-
* @param {string} text
|
|
278
|
-
* @param {number} start
|
|
279
|
-
* @
|
|
256
|
+
* @param {string} text - The string against which to match the regular expression
|
|
257
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
258
|
+
* @return {boolean}
|
|
280
259
|
*/
|
|
281
260
|
isMatchAt(text, start) {
|
|
282
261
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -285,51 +264,337 @@ export class RRegex {
|
|
|
285
264
|
return ret !== 0;
|
|
286
265
|
}
|
|
287
266
|
/**
|
|
288
|
-
* Returns the start and end byte range of the leftmost-first match in
|
|
289
|
-
*
|
|
267
|
+
* Returns the start and end byte range of the leftmost-first match in
|
|
268
|
+
* `text`. If no match exists, then `undefined` is returned.
|
|
269
|
+
*
|
|
270
|
+
* Note that this should only be used if you want to discover the position
|
|
271
|
+
* of the match. Testing the existence of a match is faster if you use
|
|
272
|
+
* `isMatch`.
|
|
273
|
+
*
|
|
274
|
+
* # Example
|
|
275
|
+
*
|
|
276
|
+
* Find the start and end location of the first word with exactly 13
|
|
277
|
+
* Unicode word characters:
|
|
278
|
+
*
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const text = "I categorically deny having triskaidekaphobia."
|
|
281
|
+
* const m = new Regex("\\b\\w{13}\\b").find(text)
|
|
282
|
+
* expect(m.start).toBe(2)
|
|
283
|
+
* expect(m.end).toBe(15)
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
290
286
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
|
|
291
|
-
* @param {string} text
|
|
292
|
-
* @
|
|
287
|
+
* @param {string} text - The string against which to match the regular expression
|
|
288
|
+
* @return {Match}
|
|
293
289
|
*/
|
|
294
290
|
find(text) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
291
|
+
try {
|
|
292
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
293
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
294
|
+
const len0 = WASM_VECTOR_LEN;
|
|
295
|
+
wasm.rregex_find(retptr, this.__wbg_ptr, ptr0, len0);
|
|
296
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
297
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
298
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
299
|
+
if (r2) {
|
|
300
|
+
throw takeObject(r1);
|
|
301
|
+
}
|
|
302
|
+
return takeObject(r0);
|
|
303
|
+
} finally {
|
|
304
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
305
|
+
}
|
|
299
306
|
}
|
|
300
307
|
/**
|
|
301
|
-
* Returns the same as find, but starts the search at the given
|
|
302
|
-
*
|
|
308
|
+
* Returns the same as find, but starts the search at the given
|
|
309
|
+
* offset.
|
|
310
|
+
*
|
|
311
|
+
* The significance of the starting point is that it takes the surrounding
|
|
312
|
+
* context into consideration. For example, the `\A` anchor can only
|
|
313
|
+
* match when `start == 0`.
|
|
314
|
+
*
|
|
303
315
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
|
|
304
|
-
* @param {string} text
|
|
305
|
-
* @param {number} start
|
|
306
|
-
* @returns {
|
|
316
|
+
* @param {string} text - The string against which to match the regular expression
|
|
317
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
318
|
+
* @returns {Match}
|
|
307
319
|
*/
|
|
308
320
|
findAt(text, start) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
321
|
+
try {
|
|
322
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
323
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
324
|
+
const len0 = WASM_VECTOR_LEN;
|
|
325
|
+
wasm.rregex_findAt(retptr, this.__wbg_ptr, ptr0, len0, start);
|
|
326
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
327
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
328
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
329
|
+
if (r2) {
|
|
330
|
+
throw takeObject(r1);
|
|
331
|
+
}
|
|
332
|
+
return takeObject(r0);
|
|
333
|
+
} finally {
|
|
334
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
335
|
+
}
|
|
313
336
|
}
|
|
314
337
|
/**
|
|
315
|
-
* Returns an array for each successive non-overlapping match in text
|
|
338
|
+
* Returns an array for each successive non-overlapping match in `text``,
|
|
339
|
+
* returning the start and end byte indices with respect to `text`.
|
|
340
|
+
*
|
|
341
|
+
* # Example
|
|
342
|
+
*
|
|
343
|
+
* Find the start and end location of every word with exactly 13 Unicode
|
|
344
|
+
* word characters:
|
|
345
|
+
*
|
|
346
|
+
* ```typescript
|
|
347
|
+
* const text = "Retroactively relinquishing remunerations is reprehensible."
|
|
348
|
+
* const matches = new Regex("\\b\\w{13}\\b").findAll(text)
|
|
349
|
+
* ```
|
|
350
|
+
*
|
|
316
351
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
|
|
317
|
-
* @param {string} text
|
|
318
|
-
* @returns {
|
|
352
|
+
* @param {string} text - The string against which to match the regular expression
|
|
353
|
+
* @returns {Match}
|
|
319
354
|
*/
|
|
320
355
|
findAll(text) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
356
|
+
try {
|
|
357
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
358
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
359
|
+
const len0 = WASM_VECTOR_LEN;
|
|
360
|
+
wasm.rregex_findAll(retptr, this.__wbg_ptr, ptr0, len0);
|
|
361
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
362
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
363
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
364
|
+
if (r2) {
|
|
365
|
+
throw takeObject(r1);
|
|
366
|
+
}
|
|
367
|
+
return takeObject(r0);
|
|
368
|
+
} finally {
|
|
369
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Returns a list of the capture names in this regex.
|
|
374
|
+
*
|
|
375
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
|
|
376
|
+
*/
|
|
377
|
+
captureNames() {
|
|
378
|
+
try {
|
|
379
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
380
|
+
wasm.rregex_captureNames(retptr, this.__wbg_ptr);
|
|
381
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
382
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
383
|
+
var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
384
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
385
|
+
return v1;
|
|
386
|
+
} finally {
|
|
387
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Returns the capture groups corresponding to the leftmost-first
|
|
392
|
+
* match in `text`. Capture group `0` always corresponds to the entire
|
|
393
|
+
* match. If no match is found, then `undefined` is returned.
|
|
394
|
+
*
|
|
395
|
+
* You should only use `captures` if you need access to the location of
|
|
396
|
+
* capturing group matches. Otherwise, `find` is faster for discovering
|
|
397
|
+
* the location of the overall match.
|
|
398
|
+
*
|
|
399
|
+
* # Examples
|
|
400
|
+
*
|
|
401
|
+
* Say you have some text with movie names and their release years,
|
|
402
|
+
* like "'Citizen Kane' (1941)". It'd be nice if we could search for text
|
|
403
|
+
* looking like that, while also extracting the movie name and its release
|
|
404
|
+
* year separately.
|
|
405
|
+
*
|
|
406
|
+
* ```typescript
|
|
407
|
+
* const re = new Regex("'([^']+)'\\s+\\((\\d{4})\)")
|
|
408
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
409
|
+
* const caps = re.captures(text)
|
|
410
|
+
* expect(caps.get[1].value).toBe("Citizen Kane")
|
|
411
|
+
* expect(caps.get[2].value).toBe("1941")
|
|
412
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
413
|
+
* ```
|
|
414
|
+
*
|
|
415
|
+
* Note that the full match is at capture group `0`. Each subsequent
|
|
416
|
+
* capture group is indexed by the order of its opening `(`.
|
|
417
|
+
*
|
|
418
|
+
* We can make this example a bit clearer by using *named* capture groups:
|
|
419
|
+
*
|
|
420
|
+
* ```typescript
|
|
421
|
+
* const re = new Regex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
|
|
422
|
+
* const text = "Not my favorite movie: 'Citizen Kane' (1941)."
|
|
423
|
+
* const caps = re.captures(text)
|
|
424
|
+
* expect(caps.name["title"].value).toBe("Citizen Kane")
|
|
425
|
+
* expect(caps.name["year"].value).toBe("1941")
|
|
426
|
+
* expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
|
|
427
|
+
* ```
|
|
428
|
+
*
|
|
429
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
|
|
430
|
+
* @param {string} text - The string against which to match the regular expression
|
|
431
|
+
* @returns {Captures|undefined}
|
|
432
|
+
*/
|
|
433
|
+
captures(text) {
|
|
434
|
+
try {
|
|
435
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
436
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
437
|
+
const len0 = WASM_VECTOR_LEN;
|
|
438
|
+
wasm.rregex_captures(retptr, this.__wbg_ptr, ptr0, len0);
|
|
439
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
440
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
441
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
442
|
+
if (r2) {
|
|
443
|
+
throw takeObject(r1);
|
|
444
|
+
}
|
|
445
|
+
return takeObject(r0);
|
|
446
|
+
} finally {
|
|
447
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Returns a list with all the non-overlapping capture groups matched
|
|
452
|
+
* in `text`. This is operationally the same as `findAll`, except it
|
|
453
|
+
* returns information about capturing group matches.
|
|
454
|
+
*
|
|
455
|
+
* # Example
|
|
456
|
+
*
|
|
457
|
+
* We can use this to find all movie titles and their release years in
|
|
458
|
+
* some text, where the movie is formatted like "'Title' (xxxx)":
|
|
459
|
+
*
|
|
460
|
+
* ```typescript
|
|
461
|
+
* const re = new Regex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
|
|
462
|
+
* const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
|
|
463
|
+
* for caps of re.captures_iter(text) {
|
|
464
|
+
* console.log(
|
|
465
|
+
* "Movie:", caps.name["title"].value, ","
|
|
466
|
+
* "Released:", caps.name["year"].value
|
|
467
|
+
* );
|
|
468
|
+
* }
|
|
469
|
+
* // Output:
|
|
470
|
+
* // Movie: Citizen Kane, Released: 1941
|
|
471
|
+
* // Movie: The Wizard of Oz, Released: 1939
|
|
472
|
+
* // Movie: M, Released: 1931
|
|
473
|
+
* ```
|
|
474
|
+
*
|
|
475
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
|
|
476
|
+
* @param {string} text - The string against which to match the regular expression
|
|
477
|
+
* @returns {Captures[]}
|
|
478
|
+
*/
|
|
479
|
+
capturesAll(text) {
|
|
480
|
+
try {
|
|
481
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
482
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
483
|
+
const len0 = WASM_VECTOR_LEN;
|
|
484
|
+
wasm.rregex_capturesAll(retptr, this.__wbg_ptr, ptr0, len0);
|
|
485
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
486
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
487
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
488
|
+
if (r2) {
|
|
489
|
+
throw takeObject(r1);
|
|
490
|
+
}
|
|
491
|
+
return takeObject(r0);
|
|
492
|
+
} finally {
|
|
493
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Returns the number of captures.
|
|
498
|
+
*
|
|
499
|
+
* This includes all named and unnamed groups, including the implicit
|
|
500
|
+
* unnamed group that is always present and corresponds to the entire match.
|
|
501
|
+
*
|
|
502
|
+
* Since the implicit unnamed group is always included in this length, the
|
|
503
|
+
* length returned is guaranteed to be greater than zero.
|
|
504
|
+
*
|
|
505
|
+
* ## Example
|
|
506
|
+
*
|
|
507
|
+
* ```typescript
|
|
508
|
+
* const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
|
|
509
|
+
* expect(re1.capturesLength()).toEqual(4)
|
|
510
|
+
*
|
|
511
|
+
* const re2 = new RRegex("foo")
|
|
512
|
+
* expect(re2.capturesLength()).toEqual(1)
|
|
513
|
+
*
|
|
514
|
+
* const re3 = new RRegex("(foo)")
|
|
515
|
+
* expect(re3.capturesLength()).toEqual(2)
|
|
516
|
+
*
|
|
517
|
+
* const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
|
|
518
|
+
* expect(re4.capturesLength()).toEqual(5)
|
|
519
|
+
*
|
|
520
|
+
* const re5 = new RRegex("[a&&b]")
|
|
521
|
+
* expect(re5.capturesLength()).toEqual(1)
|
|
522
|
+
* ```
|
|
523
|
+
*
|
|
524
|
+
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
|
|
525
|
+
* @returns {number}
|
|
526
|
+
*/
|
|
527
|
+
capturesLength() {
|
|
528
|
+
const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
|
|
529
|
+
return ret >>> 0;
|
|
325
530
|
}
|
|
326
531
|
/**
|
|
327
532
|
* Replaces the leftmost-first match with the replacement provided.
|
|
328
|
-
* The replacement can be a regular string (where `$N` and `$name` are
|
|
533
|
+
* The replacement can be a regular string (where `$N` and `$name` are
|
|
534
|
+
* expanded to match capture groups) or a function that takes the matches'
|
|
535
|
+
* `Captures` and returns the replaced string.
|
|
536
|
+
*
|
|
329
537
|
* If no match is found, then a copy of the string is returned unchanged.
|
|
538
|
+
*
|
|
539
|
+
* # Replacement string syntax
|
|
540
|
+
*
|
|
541
|
+
* All instances of `$name` in the replacement text is replaced with the
|
|
542
|
+
* corresponding capture group `name`.
|
|
543
|
+
*
|
|
544
|
+
* `name` may be an integer corresponding to the index of the
|
|
545
|
+
* capture group (counted by order of opening parenthesis where `0` is the
|
|
546
|
+
* entire match) or it can be a name (consisting of letters, digits or
|
|
547
|
+
* underscores) corresponding to a named capture group.
|
|
548
|
+
*
|
|
549
|
+
* If `name` isn't a valid capture group (whether the name doesn't exist
|
|
550
|
+
* or isn't a valid index), then it is replaced with the empty string.
|
|
551
|
+
*
|
|
552
|
+
* The longest possible name is used. e.g., `$1a` looks up the capture
|
|
553
|
+
* group named `1a` and not the capture group at index `1`. To exert more
|
|
554
|
+
* precise control over the name, use braces, e.g., `${1}a`.
|
|
555
|
+
*
|
|
556
|
+
* To write a literal `$` use `$$`.
|
|
557
|
+
*
|
|
558
|
+
* # Examples
|
|
559
|
+
*
|
|
560
|
+
* Note that this function is polymorphic with respect to the replacement.
|
|
561
|
+
* In typical usage, this can just be a normal string:
|
|
562
|
+
*
|
|
563
|
+
* ```typescript
|
|
564
|
+
* const re = new Regex("[^01]+")
|
|
565
|
+
* expect(re.replace("1078910", "").toBe("1010")
|
|
566
|
+
* ```
|
|
567
|
+
*
|
|
568
|
+
* Here's the example using this expansion technique with named capture
|
|
569
|
+
* groups:
|
|
570
|
+
*
|
|
571
|
+
* ```typescript
|
|
572
|
+
* const re = new Regex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
|
|
573
|
+
* const result = re.replace("Springsteen, Bruce", "$first $last")
|
|
574
|
+
* expect(result).toBe("Bruce Springsteen")
|
|
575
|
+
* ```
|
|
576
|
+
*
|
|
577
|
+
* Note that using `$2` instead of `$first` or `$1` instead of `$last`
|
|
578
|
+
* would produce the same result. To write a literal `$` use `$$`.
|
|
579
|
+
*
|
|
580
|
+
* Sometimes the replacement string requires use of curly braces to
|
|
581
|
+
* delineate a capture group replacement and surrounding literal text.
|
|
582
|
+
* For example, if we wanted to join two words together with an
|
|
583
|
+
* underscore:
|
|
584
|
+
*
|
|
585
|
+
* ```typescript
|
|
586
|
+
* const re = new Regex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
|
|
587
|
+
* const result = re.replace("deep fried", "${first}_$second")
|
|
588
|
+
* expect(result).toBe("deep_fried")
|
|
589
|
+
* ```
|
|
590
|
+
*
|
|
591
|
+
* Without the curly braces, the capture group name `first_` would be
|
|
592
|
+
* used, and since it doesn't exist, it would be replaced with the empty
|
|
593
|
+
* string.
|
|
594
|
+
*
|
|
330
595
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
|
|
331
|
-
* @param {string} text
|
|
332
|
-
* @param {string} rep
|
|
596
|
+
* @param {string} text - The string against which to match the regular expression
|
|
597
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
333
598
|
* @returns {string}
|
|
334
599
|
*/
|
|
335
600
|
replace(text, rep) {
|
|
@@ -353,12 +618,17 @@ export class RRegex {
|
|
|
353
618
|
}
|
|
354
619
|
}
|
|
355
620
|
/**
|
|
356
|
-
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
357
|
-
*
|
|
621
|
+
* Replaces at most `limit` non-overlapping matches in `text` with the
|
|
622
|
+
* replacement provided. If `limit` is 0, then all non-overlapping matches
|
|
623
|
+
* are replaced.
|
|
624
|
+
*
|
|
625
|
+
* See the documentation for `replace` for details on how to access
|
|
626
|
+
* capturing group matches in the replacement string.
|
|
627
|
+
*
|
|
358
628
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
|
|
359
|
-
* @param {string} text
|
|
360
|
-
* @param {number} limit
|
|
361
|
-
* @param {string} rep
|
|
629
|
+
* @param {string} text - The string against which to match the regular expression
|
|
630
|
+
* @param {number} limit - Max number of replacement
|
|
631
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
362
632
|
* @returns {string}
|
|
363
633
|
*/
|
|
364
634
|
replacen(text, limit, rep) {
|
|
@@ -382,11 +652,17 @@ export class RRegex {
|
|
|
382
652
|
}
|
|
383
653
|
}
|
|
384
654
|
/**
|
|
385
|
-
* Replaces all non-overlapping matches in `text` with the replacement
|
|
655
|
+
* Replaces all non-overlapping matches in `text` with the replacement
|
|
656
|
+
* provided. This is the same as calling `replacen` with `limit` set to
|
|
657
|
+
* `0`.
|
|
658
|
+
*
|
|
659
|
+
* See the documentation for `replace` for details on how to access
|
|
660
|
+
* capturing group matches in the replacement string.
|
|
661
|
+
*
|
|
386
662
|
* See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
|
|
387
663
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
|
|
388
|
-
* @param {string} text
|
|
389
|
-
* @param {string} rep
|
|
664
|
+
* @param {string} text - The string against which to match the regular expression
|
|
665
|
+
* @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
|
|
390
666
|
* @returns {string}
|
|
391
667
|
*/
|
|
392
668
|
replaceAll(text, rep) {
|
|
@@ -410,38 +686,109 @@ export class RRegex {
|
|
|
410
686
|
}
|
|
411
687
|
}
|
|
412
688
|
/**
|
|
413
|
-
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
414
|
-
*
|
|
689
|
+
* Returns an iterator of substrings of `text` delimited by a match of the
|
|
690
|
+
* regular expression. Namely, each element of the iterator corresponds to
|
|
691
|
+
* text that *isn't* matched by the regular expression.
|
|
692
|
+
*
|
|
693
|
+
* This method will *not* copy the text given.
|
|
694
|
+
*
|
|
695
|
+
* # Example
|
|
696
|
+
*
|
|
697
|
+
* To split a string delimited by arbitrary amounts of spaces or tabs:
|
|
698
|
+
*
|
|
699
|
+
* ```typescript
|
|
700
|
+
* const re = new Regex(r"[ \\t]+")
|
|
701
|
+
* const fields = re.split("a b \t c\td e")
|
|
702
|
+
* expect(fields).toEqual(["a", "b", "c", "d", "e"])
|
|
703
|
+
* ```
|
|
704
|
+
*
|
|
415
705
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
|
|
416
|
-
* @param {string} text
|
|
417
|
-
* @returns {
|
|
706
|
+
* @param {string} text - The string against which to match the regular expression
|
|
707
|
+
* @returns {string[]}
|
|
418
708
|
*/
|
|
419
709
|
split(text) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
710
|
+
try {
|
|
711
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
712
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
713
|
+
const len0 = WASM_VECTOR_LEN;
|
|
714
|
+
wasm.rregex_split(retptr, this.__wbg_ptr, ptr0, len0);
|
|
715
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
716
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
717
|
+
var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
718
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
719
|
+
return v2;
|
|
720
|
+
} finally {
|
|
721
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
722
|
+
}
|
|
424
723
|
}
|
|
425
724
|
/**
|
|
426
|
-
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
427
|
-
*
|
|
725
|
+
* Returns an iterator of at most `limit` substrings of `text` delimited
|
|
726
|
+
* by a match of the regular expression. (A `limit` of `0` will return no
|
|
727
|
+
* substrings.) Namely, each element of the iterator corresponds to text
|
|
728
|
+
* that *isn't* matched by the regular expression. The remainder of the
|
|
729
|
+
* string that is not split will be the last element in the iterator.
|
|
730
|
+
*
|
|
731
|
+
* This method will *not* copy the text given.
|
|
732
|
+
*
|
|
733
|
+
* # Example
|
|
734
|
+
*
|
|
735
|
+
* Get the first two words in some text:
|
|
736
|
+
*
|
|
737
|
+
* ```typescript
|
|
738
|
+
* const re = new Regex(r"\\W+")
|
|
739
|
+
* const fields = re.splitn("Hey! How are you?", 3)
|
|
740
|
+
* expect(fields).toEqual(["Hey", "How", "are you?"])
|
|
741
|
+
* ```
|
|
428
742
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
|
|
429
|
-
* @param {string} text
|
|
430
|
-
* @param {number} limit
|
|
431
|
-
* @returns {
|
|
743
|
+
* @param {string} text - The string against which to match the regular expression
|
|
744
|
+
* @param {number} limit - Max number result elements
|
|
745
|
+
* @returns {string[]}
|
|
432
746
|
*/
|
|
433
747
|
splitn(text, limit) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
748
|
+
try {
|
|
749
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
750
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
751
|
+
const len0 = WASM_VECTOR_LEN;
|
|
752
|
+
wasm.rregex_splitn(retptr, this.__wbg_ptr, ptr0, len0, limit);
|
|
753
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
754
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
755
|
+
var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
756
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
757
|
+
return v2;
|
|
758
|
+
} finally {
|
|
759
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
760
|
+
}
|
|
438
761
|
}
|
|
439
762
|
/**
|
|
440
763
|
* Returns the end location of a match in the text given.
|
|
441
|
-
*
|
|
764
|
+
*
|
|
765
|
+
* This method may have the same performance characteristics as
|
|
766
|
+
* `isMatch`, except it provides an end location for a match. In
|
|
767
|
+
* particular, the location returned *may be shorter* than the proper end
|
|
768
|
+
* of the leftmost-first match that you would find via `Regex.find`.
|
|
769
|
+
*
|
|
770
|
+
* Note that it is not guaranteed that this routine finds the shortest or
|
|
771
|
+
* "earliest" possible match. Instead, the main idea of this API is that
|
|
772
|
+
* it returns the offset at the point at which the internal regex engine
|
|
773
|
+
* has determined that a match has occurred. This may vary depending on
|
|
774
|
+
* which internal regex engine is used, and thus, the offset itself may
|
|
775
|
+
* change.
|
|
776
|
+
*
|
|
777
|
+
* # Example
|
|
778
|
+
*
|
|
779
|
+
* Typically, `a+` would match the entire first sequence of `a` in some
|
|
780
|
+
* text, but `shortest_match` can give up as soon as it sees the first
|
|
781
|
+
* `a`.
|
|
782
|
+
*
|
|
783
|
+
* ```typescript
|
|
784
|
+
* const text = "aaaaa"
|
|
785
|
+
* const = new Regex("a+").shortest_match(text)
|
|
786
|
+
* expect(pos).toBe(1)
|
|
787
|
+
* ```
|
|
788
|
+
*
|
|
442
789
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
|
|
443
|
-
* @param {string} text
|
|
444
|
-
* @returns {number
|
|
790
|
+
* @param {string} text - The string against which to match the regular expression
|
|
791
|
+
* @returns {number|undefined}
|
|
445
792
|
*/
|
|
446
793
|
shortestMatch(text) {
|
|
447
794
|
try {
|
|
@@ -457,19 +804,23 @@ export class RRegex {
|
|
|
457
804
|
}
|
|
458
805
|
}
|
|
459
806
|
/**
|
|
460
|
-
* Returns the same as shortest_match
|
|
461
|
-
*
|
|
807
|
+
* Returns the same as `shortest_match`, but starts the search at the
|
|
808
|
+
* given offset.
|
|
809
|
+
*
|
|
810
|
+
* The significance of the starting point is that it takes the surrounding
|
|
811
|
+
* context into consideration. For example, the `\A` anchor can only match
|
|
812
|
+
* when `start == 0`.
|
|
462
813
|
* @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
|
|
463
|
-
* @param {string} text
|
|
464
|
-
* @param {number}
|
|
465
|
-
* @returns {number
|
|
814
|
+
* @param {string} text - The string against which to match the regular expression
|
|
815
|
+
* @param {number} start - Zero-based index at which to start matching
|
|
816
|
+
* @returns {number|undefined}
|
|
466
817
|
*/
|
|
467
|
-
shortestMatchAt(text,
|
|
818
|
+
shortestMatchAt(text, start) {
|
|
468
819
|
try {
|
|
469
820
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
470
821
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
471
822
|
const len0 = WASM_VECTOR_LEN;
|
|
472
|
-
wasm.rregex_shortestMatchAt(retptr, this.__wbg_ptr, ptr0, len0,
|
|
823
|
+
wasm.rregex_shortestMatchAt(retptr, this.__wbg_ptr, ptr0, len0, start);
|
|
473
824
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
474
825
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
475
826
|
return r0 === 0 ? undefined : r1 >>> 0;
|
|
@@ -478,12 +829,24 @@ export class RRegex {
|
|
|
478
829
|
}
|
|
479
830
|
}
|
|
480
831
|
/**
|
|
481
|
-
*
|
|
832
|
+
* Returns the regular expression into a high level intermediate
|
|
833
|
+
* representation.
|
|
482
834
|
* @returns {any}
|
|
483
835
|
*/
|
|
484
836
|
syntax() {
|
|
485
|
-
|
|
486
|
-
|
|
837
|
+
try {
|
|
838
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
839
|
+
wasm.rregex_syntax(retptr, this.__wbg_ptr);
|
|
840
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
841
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
842
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
843
|
+
if (r2) {
|
|
844
|
+
throw takeObject(r1);
|
|
845
|
+
}
|
|
846
|
+
return takeObject(r0);
|
|
847
|
+
} finally {
|
|
848
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
849
|
+
}
|
|
487
850
|
}
|
|
488
851
|
/**
|
|
489
852
|
* Returns a string representing the regular expression
|
|
@@ -508,7 +871,14 @@ export class RRegex {
|
|
|
508
871
|
}
|
|
509
872
|
/**
|
|
510
873
|
* Match multiple (possibly overlapping) regular expressions in a single scan.
|
|
511
|
-
* A regex set corresponds to the union of two or more regular expressions.
|
|
874
|
+
* A regex set corresponds to the union of two or more regular expressions.
|
|
875
|
+
*
|
|
876
|
+
* That is, a regex set will match text where at least one of its constituent
|
|
877
|
+
* regular expressions matches. A regex set as its formulated here provides a
|
|
878
|
+
* touch more power: it will also report which regular expressions in the set match.
|
|
879
|
+
* Indeed, this is the key difference between regex sets and a single `Regex`
|
|
880
|
+
* with many alternates, since only one alternate can match at a time.
|
|
881
|
+
*
|
|
512
882
|
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
|
|
513
883
|
*/
|
|
514
884
|
export class RRegexSet {
|
|
@@ -526,6 +896,18 @@ export class RRegexSet {
|
|
|
526
896
|
}
|
|
527
897
|
/**
|
|
528
898
|
* Create a new regex set with the given regular expressions.
|
|
899
|
+
*
|
|
900
|
+
* This takes an of strings, if any item in the list is not a valid regular
|
|
901
|
+
* expressions, then an error is returned.
|
|
902
|
+
*
|
|
903
|
+
* # Example
|
|
904
|
+
*
|
|
905
|
+
* Create a new regex set from an iterator of strings:
|
|
906
|
+
*
|
|
907
|
+
* ```typescript
|
|
908
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
909
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
910
|
+
* ```
|
|
529
911
|
* @param {Array<any>} list
|
|
530
912
|
*/
|
|
531
913
|
constructor(list) {
|
|
@@ -546,11 +928,33 @@ export class RRegexSet {
|
|
|
546
928
|
}
|
|
547
929
|
}
|
|
548
930
|
/**
|
|
549
|
-
* Returns true if and only if one of the regexes in this set matches
|
|
550
|
-
*
|
|
931
|
+
* Returns true if and only if one of the regexes in this set matches
|
|
932
|
+
* the text given.
|
|
933
|
+
*
|
|
934
|
+
* This method should be preferred if you only need to test whether any
|
|
935
|
+
* of the regexes in the set should match, but don't care about *which*
|
|
936
|
+
* regexes matched. This is because the underlying matching engine will
|
|
937
|
+
* quit immediately after seeing the first match instead of continuing to
|
|
938
|
+
* find all matches.
|
|
939
|
+
*
|
|
940
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
941
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
942
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
943
|
+
* text.
|
|
944
|
+
*
|
|
945
|
+
* # Example
|
|
946
|
+
*
|
|
947
|
+
* Tests whether a set matches some text:
|
|
948
|
+
*
|
|
949
|
+
* ```typescript
|
|
950
|
+
* const set = new RegexSet(["\\w+", "\\d+"])
|
|
951
|
+
* expect(set.is_match("foo")).toBe(true)
|
|
952
|
+
* expect(!set.is_match("☃")).toBe(false)
|
|
953
|
+
* ```
|
|
954
|
+
*
|
|
551
955
|
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
|
|
552
|
-
* @param {string} text
|
|
553
|
-
* @
|
|
956
|
+
* @param {string} text - The string against which to match the regular expression
|
|
957
|
+
* @return {boolean}
|
|
554
958
|
*/
|
|
555
959
|
isMatch(text) {
|
|
556
960
|
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -560,16 +964,54 @@ export class RRegexSet {
|
|
|
560
964
|
}
|
|
561
965
|
/**
|
|
562
966
|
* Returns the set of regular expressions that match in the given text.
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
967
|
+
*
|
|
968
|
+
* The set returned contains the index of each regular expression that
|
|
969
|
+
* matches in the given text. The index is in correspondence with the
|
|
970
|
+
* order of regular expressions given to `RegexSet`'s constructor.
|
|
971
|
+
*
|
|
972
|
+
* The set can also be used to iterate over the matched indices.
|
|
973
|
+
*
|
|
974
|
+
* Note that as with searches using `Regex`, the expression is unanchored
|
|
975
|
+
* by default. That is, if the regex does not start with `^` or `\A`, or
|
|
976
|
+
* end with `$` or `\z`, then it is permitted to match anywhere in the
|
|
977
|
+
* text.
|
|
978
|
+
*
|
|
979
|
+
* # Example
|
|
980
|
+
*
|
|
981
|
+
* Tests which regular expressions match the given text:
|
|
982
|
+
*
|
|
983
|
+
* ```typescript
|
|
984
|
+
* const set = new RegexSet([
|
|
985
|
+
* "\\w+",
|
|
986
|
+
* "\\d+",
|
|
987
|
+
* "\\pL+",
|
|
988
|
+
* "foo",
|
|
989
|
+
* "bar",
|
|
990
|
+
* "barfoo",
|
|
991
|
+
* "foobar",
|
|
992
|
+
* ])
|
|
993
|
+
* const matches = set.matches("foobar")
|
|
994
|
+
* expect(matches).toBe([0, 2, 3, 4, 6])
|
|
995
|
+
* ```
|
|
996
|
+
*
|
|
997
|
+
* @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
|
|
998
|
+
* @param {string} text - The string against which to match the regular expression
|
|
999
|
+
* @return {number[]}
|
|
567
1000
|
*/
|
|
568
1001
|
matches(text) {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
1002
|
+
try {
|
|
1003
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1004
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1005
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1006
|
+
wasm.rregexset_matches(retptr, this.__wbg_ptr, ptr0, len0);
|
|
1007
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
1008
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
1009
|
+
var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
|
|
1010
|
+
wasm.__wbindgen_free(r0, r1 * 4, 4);
|
|
1011
|
+
return v2;
|
|
1012
|
+
} finally {
|
|
1013
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
1014
|
+
}
|
|
573
1015
|
}
|
|
574
1016
|
}
|
|
575
1017
|
|
|
@@ -607,6 +1049,10 @@ async function __wbg_load(module, imports) {
|
|
|
607
1049
|
function __wbg_get_imports() {
|
|
608
1050
|
const imports = {};
|
|
609
1051
|
imports.wbg = {};
|
|
1052
|
+
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
1053
|
+
const ret = arg0;
|
|
1054
|
+
return addHeapObject(ret);
|
|
1055
|
+
};
|
|
610
1056
|
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
611
1057
|
takeObject(arg0);
|
|
612
1058
|
};
|
|
@@ -614,14 +1060,6 @@ function __wbg_get_imports() {
|
|
|
614
1060
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
615
1061
|
return addHeapObject(ret);
|
|
616
1062
|
};
|
|
617
|
-
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
618
|
-
const ret = arg0;
|
|
619
|
-
return addHeapObject(ret);
|
|
620
|
-
};
|
|
621
|
-
imports.wbg.__wbindgen_is_string = function(arg0) {
|
|
622
|
-
const ret = typeof(getObject(arg0)) === 'string';
|
|
623
|
-
return ret;
|
|
624
|
-
};
|
|
625
1063
|
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
|
|
626
1064
|
const obj = getObject(arg1);
|
|
627
1065
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
@@ -630,6 +1068,21 @@ function __wbg_get_imports() {
|
|
|
630
1068
|
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
631
1069
|
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
632
1070
|
};
|
|
1071
|
+
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
|
1072
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
1073
|
+
return addHeapObject(ret);
|
|
1074
|
+
};
|
|
1075
|
+
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
|
1076
|
+
const ret = getObject(arg0);
|
|
1077
|
+
return addHeapObject(ret);
|
|
1078
|
+
};
|
|
1079
|
+
imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
|
|
1080
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
1081
|
+
return addHeapObject(ret);
|
|
1082
|
+
};
|
|
1083
|
+
imports.wbg.__wbg_set_9182712abebf82ef = function(arg0, arg1, arg2) {
|
|
1084
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
1085
|
+
};
|
|
633
1086
|
imports.wbg.__wbg_get_f01601b5a68d10e3 = function(arg0, arg1) {
|
|
634
1087
|
const ret = getObject(arg0)[arg1 >>> 0];
|
|
635
1088
|
return addHeapObject(ret);
|
|
@@ -646,28 +1099,44 @@ function __wbg_get_imports() {
|
|
|
646
1099
|
const ret = new Object();
|
|
647
1100
|
return addHeapObject(ret);
|
|
648
1101
|
};
|
|
1102
|
+
imports.wbg.__wbg_set_f2740edb12e318cd = function(arg0, arg1, arg2) {
|
|
1103
|
+
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
1104
|
+
};
|
|
1105
|
+
imports.wbg.__wbg_from_71add2e723d1f1b2 = function(arg0) {
|
|
1106
|
+
const ret = Array.from(getObject(arg0));
|
|
1107
|
+
return addHeapObject(ret);
|
|
1108
|
+
};
|
|
649
1109
|
imports.wbg.__wbg_push_901f3914205d44de = function(arg0, arg1) {
|
|
650
1110
|
const ret = getObject(arg0).push(getObject(arg1));
|
|
651
1111
|
return ret;
|
|
652
1112
|
};
|
|
653
|
-
imports.wbg.
|
|
654
|
-
const ret =
|
|
1113
|
+
imports.wbg.__wbg_fromCodePoint_fd9383eff8873c75 = function() { return handleError(function (arg0) {
|
|
1114
|
+
const ret = String.fromCodePoint(arg0 >>> 0);
|
|
1115
|
+
return addHeapObject(ret);
|
|
1116
|
+
}, arguments) };
|
|
1117
|
+
imports.wbg.__wbg_buffer_a448f833075b71ba = function(arg0) {
|
|
1118
|
+
const ret = getObject(arg0).buffer;
|
|
1119
|
+
return addHeapObject(ret);
|
|
1120
|
+
};
|
|
1121
|
+
imports.wbg.__wbg_newwithbyteoffsetandlength_d0482f893617af71 = function(arg0, arg1, arg2) {
|
|
1122
|
+
const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
|
|
1123
|
+
return addHeapObject(ret);
|
|
1124
|
+
};
|
|
1125
|
+
imports.wbg.__wbg_new_8f67e318f15d7254 = function(arg0) {
|
|
1126
|
+
const ret = new Uint8Array(getObject(arg0));
|
|
655
1127
|
return addHeapObject(ret);
|
|
656
1128
|
};
|
|
657
1129
|
imports.wbg.__wbg_set_759f75cd92b612d2 = function() { return handleError(function (arg0, arg1, arg2) {
|
|
658
1130
|
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
|
|
659
1131
|
return ret;
|
|
660
1132
|
}, arguments) };
|
|
661
|
-
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
|
|
662
|
-
const ret = debugString(getObject(arg1));
|
|
663
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
664
|
-
const len1 = WASM_VECTOR_LEN;
|
|
665
|
-
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
|
666
|
-
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
|
667
|
-
};
|
|
668
1133
|
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
669
1134
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
670
1135
|
};
|
|
1136
|
+
imports.wbg.__wbindgen_memory = function() {
|
|
1137
|
+
const ret = wasm.memory;
|
|
1138
|
+
return addHeapObject(ret);
|
|
1139
|
+
};
|
|
671
1140
|
|
|
672
1141
|
return imports;
|
|
673
1142
|
}
|
|
@@ -680,6 +1149,7 @@ function __wbg_finalize_init(instance, module) {
|
|
|
680
1149
|
wasm = instance.exports;
|
|
681
1150
|
__wbg_init.__wbindgen_wasm_module = module;
|
|
682
1151
|
cachedInt32Memory0 = null;
|
|
1152
|
+
cachedUint32Memory0 = null;
|
|
683
1153
|
cachedUint8Memory0 = null;
|
|
684
1154
|
|
|
685
1155
|
|
|
@@ -730,8 +1200,8 @@ export const metadata = {
|
|
|
730
1200
|
"authors": [
|
|
731
1201
|
"Fede Ramirez <i@2fd.me>"
|
|
732
1202
|
],
|
|
733
|
-
"homepage": "
|
|
1203
|
+
"homepage": "http://rregex.dev",
|
|
734
1204
|
"repository": "https://github.com/2fd/rregex",
|
|
735
|
-
"regex": "1.
|
|
736
|
-
"regex-syntax": "0.
|
|
1205
|
+
"regex": "1.9.6",
|
|
1206
|
+
"regex-syntax": "0.7.5"
|
|
737
1207
|
}
|