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