rregex 1.9.0 → 1.9.2

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/lib/module.js DELETED
@@ -1,1135 +0,0 @@
1
- let wasm;
2
- export function __wbg_set_wasm(val) {
3
- wasm = val;
4
- }
5
-
6
-
7
- const heap = new Array(128).fill(undefined);
8
-
9
- heap.push(undefined, null, true, false);
10
-
11
- let heap_next = heap.length;
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
-
24
- function dropObject(idx) {
25
- if (idx < 132) return;
26
- heap[idx] = heap_next;
27
- heap_next = idx;
28
- }
29
-
30
- function takeObject(idx) {
31
- const ret = getObject(idx);
32
- dropObject(idx);
33
- return ret;
34
- }
35
-
36
- const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
37
-
38
- let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
39
-
40
- cachedTextDecoder.decode();
41
-
42
- let cachedUint8Memory0 = null;
43
-
44
- function getUint8Memory0() {
45
- if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
46
- cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
47
- }
48
- return cachedUint8Memory0;
49
- }
50
-
51
- function getStringFromWasm0(ptr, len) {
52
- ptr = ptr >>> 0;
53
- return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
54
- }
55
-
56
- let WASM_VECTOR_LEN = 0;
57
-
58
- const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
59
-
60
- let cachedTextEncoder = new lTextEncoder('utf-8');
61
-
62
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
63
- ? function (arg, view) {
64
- return cachedTextEncoder.encodeInto(arg, view);
65
- }
66
- : function (arg, view) {
67
- const buf = cachedTextEncoder.encode(arg);
68
- view.set(buf);
69
- return {
70
- read: arg.length,
71
- written: buf.length
72
- };
73
- });
74
-
75
- function passStringToWasm0(arg, malloc, realloc) {
76
-
77
- if (realloc === undefined) {
78
- const buf = cachedTextEncoder.encode(arg);
79
- const ptr = malloc(buf.length, 1) >>> 0;
80
- getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
81
- WASM_VECTOR_LEN = buf.length;
82
- return ptr;
83
- }
84
-
85
- let len = arg.length;
86
- let ptr = malloc(len, 1) >>> 0;
87
-
88
- const mem = getUint8Memory0();
89
-
90
- let offset = 0;
91
-
92
- for (; offset < len; offset++) {
93
- const code = arg.charCodeAt(offset);
94
- if (code > 0x7F) break;
95
- mem[ptr + offset] = code;
96
- }
97
-
98
- if (offset !== len) {
99
- if (offset !== 0) {
100
- arg = arg.slice(offset);
101
- }
102
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
103
- const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
104
- const ret = encodeString(arg, view);
105
-
106
- offset += ret.written;
107
- }
108
-
109
- WASM_VECTOR_LEN = offset;
110
- return ptr;
111
- }
112
-
113
- function isLikeNone(x) {
114
- return x === undefined || x === null;
115
- }
116
-
117
- let cachedInt32Memory0 = null;
118
-
119
- function getInt32Memory0() {
120
- if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
121
- cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
122
- }
123
- return cachedInt32Memory0;
124
- }
125
-
126
- let cachedUint32Memory0 = null;
127
-
128
- function getUint32Memory0() {
129
- if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
130
- cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
131
- }
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]));
142
- }
143
- return result;
144
- }
145
-
146
- let stack_pointer = 128;
147
-
148
- function addBorrowedObject(obj) {
149
- if (stack_pointer == 1) throw new Error('out of js stack');
150
- heap[--stack_pointer] = obj;
151
- return stack_pointer;
152
- }
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.
158
- * @param {string} text
159
- * @returns {string}
160
- */
161
- export function escape(text) {
162
- let deferred2_0;
163
- let deferred2_1;
164
- try {
165
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
166
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
167
- const len0 = WASM_VECTOR_LEN;
168
- wasm.escape(retptr, ptr0, len0);
169
- var r0 = getInt32Memory0()[retptr / 4 + 0];
170
- var r1 = getInt32Memory0()[retptr / 4 + 1];
171
- deferred2_0 = r0;
172
- deferred2_1 = r1;
173
- return getStringFromWasm0(r0, r1);
174
- } finally {
175
- wasm.__wbindgen_add_to_stack_pointer(16);
176
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
177
- }
178
- }
179
-
180
- function handleError(f, args) {
181
- try {
182
- return f.apply(this, args);
183
- } catch (e) {
184
- wasm.__wbindgen_exn_store(addHeapObject(e));
185
- }
186
- }
187
- /**
188
- * A compiled regular expression for matching Unicode strings.
189
- * @see https://docs.rs/regex/latest/regex/
190
- */
191
- export class RRegex {
192
-
193
- __destroy_into_raw() {
194
- const ptr = this.__wbg_ptr;
195
- this.__wbg_ptr = 0;
196
-
197
- return ptr;
198
- }
199
-
200
- free() {
201
- const ptr = this.__destroy_into_raw();
202
- wasm.__wbg_rregex_free(ptr);
203
- }
204
- /**
205
- * Compiles a regular expression. Once compiled, it can be used repeatedly
206
- * to search, split or replace text in a string.
207
- *
208
- * If an invalid expression is given, then an error is returned.
209
- * @param {string} re
210
- */
211
- constructor(re) {
212
- try {
213
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
214
- const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
215
- const len0 = WASM_VECTOR_LEN;
216
- wasm.rregex_new(retptr, ptr0, len0);
217
- var r0 = getInt32Memory0()[retptr / 4 + 0];
218
- var r1 = getInt32Memory0()[retptr / 4 + 1];
219
- var r2 = getInt32Memory0()[retptr / 4 + 2];
220
- if (r2) {
221
- throw takeObject(r1);
222
- }
223
- this.__wbg_ptr = r0 >>> 0;
224
- return this;
225
- } finally {
226
- wasm.__wbindgen_add_to_stack_pointer(16);
227
- }
228
- }
229
- /**
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
- *
247
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
248
- * @param {string} text - The string against which to match the regular expression
249
- * @return {boolean}
250
- */
251
- isMatch(text) {
252
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
253
- const len0 = WASM_VECTOR_LEN;
254
- const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
255
- return ret !== 0;
256
- }
257
- /**
258
- * Returns the same as is_match, but starts the search at the given offset.
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
- *
263
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
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}
267
- */
268
- isMatchAt(text, start) {
269
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
270
- const len0 = WASM_VECTOR_LEN;
271
- const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
272
- return ret !== 0;
273
- }
274
- /**
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
- *
294
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
295
- * @param {string} text - The string against which to match the regular expression
296
- * @return {Match}
297
- */
298
- find(text) {
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
- }
314
- }
315
- /**
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
- *
323
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
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}
327
- */
328
- findAt(text, start) {
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
- }
344
- }
345
- /**
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
- *
359
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
360
- * @param {string} text - The string against which to match the regular expression
361
- * @returns {Match}
362
- */
363
- findAll(text) {
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;
538
- }
539
- /**
540
- * Replaces the leftmost-first match with the replacement provided.
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
- *
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
- *
603
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
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`.
606
- * @returns {string}
607
- */
608
- replace(text, rep) {
609
- let deferred3_0;
610
- let deferred3_1;
611
- try {
612
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
613
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
614
- const len0 = WASM_VECTOR_LEN;
615
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
616
- const len1 = WASM_VECTOR_LEN;
617
- wasm.rregex_replace(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
618
- var r0 = getInt32Memory0()[retptr / 4 + 0];
619
- var r1 = getInt32Memory0()[retptr / 4 + 1];
620
- deferred3_0 = r0;
621
- deferred3_1 = r1;
622
- return getStringFromWasm0(r0, r1);
623
- } finally {
624
- wasm.__wbindgen_add_to_stack_pointer(16);
625
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
626
- }
627
- }
628
- /**
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
- *
636
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
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`.
640
- * @returns {string}
641
- */
642
- replacen(text, limit, rep) {
643
- let deferred3_0;
644
- let deferred3_1;
645
- try {
646
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
647
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
648
- const len0 = WASM_VECTOR_LEN;
649
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
650
- const len1 = WASM_VECTOR_LEN;
651
- wasm.rregex_replacen(retptr, this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
652
- var r0 = getInt32Memory0()[retptr / 4 + 0];
653
- var r1 = getInt32Memory0()[retptr / 4 + 1];
654
- deferred3_0 = r0;
655
- deferred3_1 = r1;
656
- return getStringFromWasm0(r0, r1);
657
- } finally {
658
- wasm.__wbindgen_add_to_stack_pointer(16);
659
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
660
- }
661
- }
662
- /**
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
- *
670
- * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
671
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
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`.
674
- * @returns {string}
675
- */
676
- replaceAll(text, rep) {
677
- let deferred3_0;
678
- let deferred3_1;
679
- try {
680
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
681
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
682
- const len0 = WASM_VECTOR_LEN;
683
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
684
- const len1 = WASM_VECTOR_LEN;
685
- wasm.rregex_replaceAll(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
686
- var r0 = getInt32Memory0()[retptr / 4 + 0];
687
- var r1 = getInt32Memory0()[retptr / 4 + 1];
688
- deferred3_0 = r0;
689
- deferred3_1 = r1;
690
- return getStringFromWasm0(r0, r1);
691
- } finally {
692
- wasm.__wbindgen_add_to_stack_pointer(16);
693
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
694
- }
695
- }
696
- /**
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
- *
713
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
714
- * @param {string} text - The string against which to match the regular expression
715
- * @returns {string[]}
716
- */
717
- split(text) {
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
- }
731
- }
732
- /**
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
- * ```
750
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
751
- * @param {string} text - The string against which to match the regular expression
752
- * @param {number} limit - Max number result elements
753
- * @returns {string[]}
754
- */
755
- splitn(text, limit) {
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
- }
769
- }
770
- /**
771
- * Returns the end location of a match in the text given.
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
- *
797
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
798
- * @param {string} text - The string against which to match the regular expression
799
- * @returns {number|undefined}
800
- */
801
- shortestMatch(text) {
802
- try {
803
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
804
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
805
- const len0 = WASM_VECTOR_LEN;
806
- wasm.rregex_shortestMatch(retptr, this.__wbg_ptr, ptr0, len0);
807
- var r0 = getInt32Memory0()[retptr / 4 + 0];
808
- var r1 = getInt32Memory0()[retptr / 4 + 1];
809
- return r0 === 0 ? undefined : r1 >>> 0;
810
- } finally {
811
- wasm.__wbindgen_add_to_stack_pointer(16);
812
- }
813
- }
814
- /**
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`.
821
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
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}
825
- */
826
- shortestMatchAt(text, start) {
827
- try {
828
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
829
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
830
- const len0 = WASM_VECTOR_LEN;
831
- wasm.rregex_shortestMatchAt(retptr, this.__wbg_ptr, ptr0, len0, start);
832
- var r0 = getInt32Memory0()[retptr / 4 + 0];
833
- var r1 = getInt32Memory0()[retptr / 4 + 1];
834
- return r0 === 0 ? undefined : r1 >>> 0;
835
- } finally {
836
- wasm.__wbindgen_add_to_stack_pointer(16);
837
- }
838
- }
839
- /**
840
- * Returns the regular expression into a high level intermediate
841
- * representation.
842
- * @returns {any}
843
- */
844
- syntax() {
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
- }
858
- }
859
- /**
860
- * Returns a string representing the regular expression
861
- * @returns {string}
862
- */
863
- toString() {
864
- let deferred1_0;
865
- let deferred1_1;
866
- try {
867
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
868
- wasm.rregex_toString(retptr, this.__wbg_ptr);
869
- var r0 = getInt32Memory0()[retptr / 4 + 0];
870
- var r1 = getInt32Memory0()[retptr / 4 + 1];
871
- deferred1_0 = r0;
872
- deferred1_1 = r1;
873
- return getStringFromWasm0(r0, r1);
874
- } finally {
875
- wasm.__wbindgen_add_to_stack_pointer(16);
876
- wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
877
- }
878
- }
879
- }
880
- /**
881
- * Match multiple (possibly overlapping) regular expressions in a single scan.
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
- *
890
- * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
891
- */
892
- export class RRegexSet {
893
-
894
- __destroy_into_raw() {
895
- const ptr = this.__wbg_ptr;
896
- this.__wbg_ptr = 0;
897
-
898
- return ptr;
899
- }
900
-
901
- free() {
902
- const ptr = this.__destroy_into_raw();
903
- wasm.__wbg_rregexset_free(ptr);
904
- }
905
- /**
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
- * ```
919
- * @param {Array<any>} list
920
- */
921
- constructor(list) {
922
- try {
923
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
924
- wasm.rregexset_new(retptr, addBorrowedObject(list));
925
- var r0 = getInt32Memory0()[retptr / 4 + 0];
926
- var r1 = getInt32Memory0()[retptr / 4 + 1];
927
- var r2 = getInt32Memory0()[retptr / 4 + 2];
928
- if (r2) {
929
- throw takeObject(r1);
930
- }
931
- this.__wbg_ptr = r0 >>> 0;
932
- return this;
933
- } finally {
934
- wasm.__wbindgen_add_to_stack_pointer(16);
935
- heap[stack_pointer++] = undefined;
936
- }
937
- }
938
- /**
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
- *
963
- * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
964
- * @param {string} text - The string against which to match the regular expression
965
- * @return {boolean}
966
- */
967
- isMatch(text) {
968
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
969
- const len0 = WASM_VECTOR_LEN;
970
- const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
971
- return ret !== 0;
972
- }
973
- /**
974
- * Returns the set of regular expressions that match in the given text.
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[]}
1008
- */
1009
- matches(text) {
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
- }
1023
- }
1024
- }
1025
-
1026
- export function __wbindgen_number_new(arg0) {
1027
- const ret = arg0;
1028
- return addHeapObject(ret);
1029
- };
1030
-
1031
- export function __wbindgen_object_drop_ref(arg0) {
1032
- takeObject(arg0);
1033
- };
1034
-
1035
- export function __wbindgen_string_new(arg0, arg1) {
1036
- const ret = getStringFromWasm0(arg0, arg1);
1037
- return addHeapObject(ret);
1038
- };
1039
-
1040
- export function __wbindgen_string_get(arg0, arg1) {
1041
- const obj = getObject(arg1);
1042
- const ret = typeof(obj) === 'string' ? obj : undefined;
1043
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1044
- var len1 = WASM_VECTOR_LEN;
1045
- getInt32Memory0()[arg0 / 4 + 1] = len1;
1046
- getInt32Memory0()[arg0 / 4 + 0] = ptr1;
1047
- };
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
-
1068
- export function __wbg_get_f01601b5a68d10e3(arg0, arg1) {
1069
- const ret = getObject(arg0)[arg1 >>> 0];
1070
- return addHeapObject(ret);
1071
- };
1072
-
1073
- export function __wbg_length_1009b1af0c481d7b(arg0) {
1074
- const ret = getObject(arg0).length;
1075
- return ret;
1076
- };
1077
-
1078
- export function __wbg_new_ffc6d4d085022169() {
1079
- const ret = new Array();
1080
- return addHeapObject(ret);
1081
- };
1082
-
1083
- export function __wbg_new_9fb8d994e1c0aaac() {
1084
- const ret = new Object();
1085
- return addHeapObject(ret);
1086
- };
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
-
1097
- export function __wbg_push_901f3914205d44de(arg0, arg1) {
1098
- const ret = getObject(arg0).push(getObject(arg1));
1099
- return ret;
1100
- };
1101
-
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));
1119
- return addHeapObject(ret);
1120
- };
1121
-
1122
- export function __wbg_set_759f75cd92b612d2() { return handleError(function (arg0, arg1, arg2) {
1123
- const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
1124
- return ret;
1125
- }, arguments) };
1126
-
1127
- export function __wbindgen_throw(arg0, arg1) {
1128
- throw new Error(getStringFromWasm0(arg0, arg1));
1129
- };
1130
-
1131
- export function __wbindgen_memory() {
1132
- const ret = wasm.memory;
1133
- return addHeapObject(ret);
1134
- };
1135
-