rregex 1.10.11 → 1.11.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/lib/commonjs.cjs CHANGED
@@ -1,53 +1,40 @@
1
+
1
2
  let imports = {};
2
3
  imports['wbg'] = module.exports;
3
4
  let wasm;
4
5
  const { TextDecoder, TextEncoder } = require(`util`);
5
6
 
7
+ function addToExternrefTable0(obj) {
8
+ const idx = wasm.__externref_table_alloc();
9
+ wasm.__wbindgen_export_2.set(idx, obj);
10
+ return idx;
11
+ }
12
+
13
+ function handleError(f, args) {
14
+ try {
15
+ return f.apply(this, args);
16
+ } catch (e) {
17
+ const idx = addToExternrefTable0(e);
18
+ wasm.__wbindgen_exn_store(idx);
19
+ }
20
+ }
21
+
6
22
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
7
23
 
8
24
  cachedTextDecoder.decode();
9
25
 
10
- let cachedUint8Memory0 = null;
26
+ let cachedUint8ArrayMemory0 = null;
11
27
 
12
- function getUint8Memory0() {
13
- if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
14
- cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
28
+ function getUint8ArrayMemory0() {
29
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
30
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
15
31
  }
16
- return cachedUint8Memory0;
32
+ return cachedUint8ArrayMemory0;
17
33
  }
18
34
 
19
35
  function getStringFromWasm0(ptr, len) {
20
36
  ptr = ptr >>> 0;
21
- return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
22
- }
23
-
24
- const heap = new Array(128).fill(undefined);
25
-
26
- heap.push(undefined, null, true, false);
27
-
28
- let heap_next = heap.length;
29
-
30
- function addHeapObject(obj) {
31
- if (heap_next === heap.length) heap.push(heap.length + 1);
32
- const idx = heap_next;
33
- heap_next = heap[idx];
34
-
35
- heap[idx] = obj;
36
- return idx;
37
- }
38
-
39
- function getObject(idx) { return heap[idx]; }
40
-
41
- function dropObject(idx) {
42
- if (idx < 132) return;
43
- heap[idx] = heap_next;
44
- heap_next = idx;
45
- }
46
-
47
- function takeObject(idx) {
48
- const ret = getObject(idx);
49
- dropObject(idx);
50
- return ret;
37
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
51
38
  }
52
39
 
53
40
  let WASM_VECTOR_LEN = 0;
@@ -72,7 +59,7 @@ function passStringToWasm0(arg, malloc, realloc) {
72
59
  if (realloc === undefined) {
73
60
  const buf = cachedTextEncoder.encode(arg);
74
61
  const ptr = malloc(buf.length, 1) >>> 0;
75
- getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
62
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
76
63
  WASM_VECTOR_LEN = buf.length;
77
64
  return ptr;
78
65
  }
@@ -80,7 +67,7 @@ function passStringToWasm0(arg, malloc, realloc) {
80
67
  let len = arg.length;
81
68
  let ptr = malloc(len, 1) >>> 0;
82
69
 
83
- const mem = getUint8Memory0();
70
+ const mem = getUint8ArrayMemory0();
84
71
 
85
72
  let offset = 0;
86
73
 
@@ -95,7 +82,7 @@ function passStringToWasm0(arg, malloc, realloc) {
95
82
  arg = arg.slice(offset);
96
83
  }
97
84
  ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
98
- const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
85
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
99
86
  const ret = encodeString(arg, view);
100
87
 
101
88
  offset += ret.written;
@@ -110,121 +97,98 @@ function isLikeNone(x) {
110
97
  return x === undefined || x === null;
111
98
  }
112
99
 
113
- let cachedInt32Memory0 = null;
100
+ let cachedDataViewMemory0 = null;
114
101
 
115
- function getInt32Memory0() {
116
- if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
117
- cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
102
+ function getDataViewMemory0() {
103
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
104
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
118
105
  }
119
- return cachedInt32Memory0;
106
+ return cachedDataViewMemory0;
120
107
  }
121
108
 
122
- let cachedUint32Memory0 = null;
123
-
124
- function getUint32Memory0() {
125
- if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) {
126
- cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer);
127
- }
128
- return cachedUint32Memory0;
109
+ function takeFromExternrefTable0(idx) {
110
+ const value = wasm.__wbindgen_export_2.get(idx);
111
+ wasm.__externref_table_dealloc(idx);
112
+ return value;
129
113
  }
130
114
 
131
115
  function getArrayJsValueFromWasm0(ptr, len) {
132
116
  ptr = ptr >>> 0;
133
- const mem = getUint32Memory0();
134
- const slice = mem.subarray(ptr / 4, ptr / 4 + len);
117
+ const mem = getDataViewMemory0();
135
118
  const result = [];
136
- for (let i = 0; i < slice.length; i++) {
137
- result.push(takeObject(slice[i]));
119
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
120
+ result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true)));
138
121
  }
122
+ wasm.__externref_drop_slice(ptr, len);
139
123
  return result;
140
124
  }
141
-
142
- let stack_pointer = 128;
143
-
144
- function addBorrowedObject(obj) {
145
- if (stack_pointer == 1) throw new Error('out of js stack');
146
- heap[--stack_pointer] = obj;
147
- return stack_pointer;
148
- }
149
125
  /**
150
- * Escapes all regular expression meta characters in `text`.
151
- *
152
- * The string returned may be safely used as a literal in a regular
153
- * expression.
154
- * @param {string} text
155
- * @returns {string}
156
- */
126
+ * Escapes all regular expression meta characters in `text`.
127
+ *
128
+ * The string returned may be safely used as a literal in a regular
129
+ * expression.
130
+ * @param {string} text
131
+ * @returns {string}
132
+ */
157
133
  module.exports.escape = function(text) {
158
134
  let deferred2_0;
159
135
  let deferred2_1;
160
136
  try {
161
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
162
137
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
163
138
  const len0 = WASM_VECTOR_LEN;
164
- wasm.escape(retptr, ptr0, len0);
165
- var r0 = getInt32Memory0()[retptr / 4 + 0];
166
- var r1 = getInt32Memory0()[retptr / 4 + 1];
167
- deferred2_0 = r0;
168
- deferred2_1 = r1;
169
- return getStringFromWasm0(r0, r1);
139
+ const ret = wasm.escape(ptr0, len0);
140
+ deferred2_0 = ret[0];
141
+ deferred2_1 = ret[1];
142
+ return getStringFromWasm0(ret[0], ret[1]);
170
143
  } finally {
171
- wasm.__wbindgen_add_to_stack_pointer(16);
172
144
  wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
173
145
  }
174
146
  };
175
147
 
176
- function handleError(f, args) {
177
- try {
178
- return f.apply(this, args);
179
- } catch (e) {
180
- wasm.__wbindgen_exn_store(addHeapObject(e));
181
- }
182
- }
183
-
184
148
  const RRegexFinalization = (typeof FinalizationRegistry === 'undefined')
185
149
  ? { register: () => {}, unregister: () => {} }
186
- : new FinalizationRegistry(ptr => wasm.__wbg_rregex_free(ptr >>> 0));
150
+ : new FinalizationRegistry(ptr => wasm.__wbg_rregex_free(ptr >>> 0, 1));
187
151
  /**
188
- * A compiled regular expression for matching Unicode strings.
189
- *
190
- * A `RRegex` can be used to search haystacks, split haystacks into substrings
191
- * or replace substrings in a haystack with a different substring. All
192
- * searching is done with an implicit `(?s:.)*?` at the beginning and end of
193
- * an pattern. To force an expression to match the whole string (or a prefix
194
- * or a suffix), you must use an anchor like `^` or `$` (or `\A` and `\z`).
195
- *
196
- * While this library will handle Unicode strings (whether in the regular
197
- * expression or in the haystack), all positions returned are **byte
198
- * offsets**. Every byte offset is guaranteed to be at a Unicode code point
199
- * boundary. That is, all offsets returned by the `RRegex` API are guaranteed
200
- * to be ranges that can slice an `Uint8Array` created with a TextEncoder.
201
- *
202
- * # Example: slicing over UTF strings
203
- *
204
- * ```typescript
205
- * import { RRegex } from "rregex"
206
- *
207
- * const re = new RRegex("ä")
208
- * const m = re.find("äöü") // { start: 0, end: 2 }
209
- *
210
- * const buff = new TextEncoder().encode("äöü")
211
- * const slice = buff.slice(m.start, m.end)
212
- * expect(new TextDecoder().decode(slice)).toBe("ä")
213
- * ```
214
- *
215
- * # Example: find the offsets of a US phone number:
216
- *
217
- * ```typescript
218
- * import { RRegex } from "rregex"
219
- *
220
- * const re = new RRegex("[0-9]{3}-[0-9]{3}-[0-9]{4}");
221
- * const m = re.find("phone: 111-222-3333");
222
- * expect(m.start).toBe(7);
223
- * expect(m.end).toBe(19);
224
- * ```
225
- *
226
- * @see https://docs.rs/regex/latest/regex/
227
- */
152
+ * A compiled regular expression for matching Unicode strings.
153
+ *
154
+ * A `RRegex` can be used to search haystacks, split haystacks into substrings
155
+ * or replace substrings in a haystack with a different substring. All
156
+ * searching is done with an implicit `(?s:.)*?` at the beginning and end of
157
+ * an pattern. To force an expression to match the whole string (or a prefix
158
+ * or a suffix), you must use an anchor like `^` or `$` (or `\A` and `\z`).
159
+ *
160
+ * While this library will handle Unicode strings (whether in the regular
161
+ * expression or in the haystack), all positions returned are **byte
162
+ * offsets**. Every byte offset is guaranteed to be at a Unicode code point
163
+ * boundary. That is, all offsets returned by the `RRegex` API are guaranteed
164
+ * to be ranges that can slice an `Uint8Array` created with a TextEncoder.
165
+ *
166
+ * # Example: slicing over UTF strings
167
+ *
168
+ * ```typescript
169
+ * import { RRegex } from "rregex"
170
+ *
171
+ * const re = new RRegex("ä")
172
+ * const m = re.find("äöü") // { start: 0, end: 2 }
173
+ *
174
+ * const buff = new TextEncoder().encode("äöü")
175
+ * const slice = buff.slice(m.start, m.end)
176
+ * expect(new TextDecoder().decode(slice)).toBe("ä")
177
+ * ```
178
+ *
179
+ * # Example: find the offsets of a US phone number:
180
+ *
181
+ * ```typescript
182
+ * import { RRegex } from "rregex"
183
+ *
184
+ * const re = new RRegex("[0-9]{3}-[0-9]{3}-[0-9]{4}");
185
+ * const m = re.find("phone: 111-222-3333");
186
+ * expect(m.start).toBe(7);
187
+ * expect(m.end).toBe(19);
188
+ * ```
189
+ *
190
+ * @see https://docs.rs/regex/latest/regex/
191
+ */
228
192
  class RRegex {
229
193
 
230
194
  __destroy_into_raw() {
@@ -236,57 +200,50 @@ class RRegex {
236
200
 
237
201
  free() {
238
202
  const ptr = this.__destroy_into_raw();
239
- wasm.__wbg_rregex_free(ptr);
203
+ wasm.__wbg_rregex_free(ptr, 0);
240
204
  }
241
205
  /**
242
- * Compiles a regular expression. Once compiled, it can be used repeatedly
243
- * to search, split or replace text in a string.
244
- *
245
- * If an invalid expression is given, then an error is returned.
246
- * @param {string} re
247
- */
206
+ * Compiles a regular expression. Once compiled, it can be used repeatedly
207
+ * to search, split or replace text in a string.
208
+ *
209
+ * If an invalid expression is given, then an error is returned.
210
+ * @param {string} re
211
+ */
248
212
  constructor(re) {
249
- try {
250
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
251
- const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
252
- const len0 = WASM_VECTOR_LEN;
253
- wasm.rregex_new(retptr, ptr0, len0);
254
- var r0 = getInt32Memory0()[retptr / 4 + 0];
255
- var r1 = getInt32Memory0()[retptr / 4 + 1];
256
- var r2 = getInt32Memory0()[retptr / 4 + 2];
257
- if (r2) {
258
- throw takeObject(r1);
259
- }
260
- this.__wbg_ptr = r0 >>> 0;
261
- return this;
262
- } finally {
263
- wasm.__wbindgen_add_to_stack_pointer(16);
213
+ const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
214
+ const len0 = WASM_VECTOR_LEN;
215
+ const ret = wasm.rregex_new(ptr0, len0);
216
+ if (ret[2]) {
217
+ throw takeFromExternrefTable0(ret[1]);
264
218
  }
219
+ this.__wbg_ptr = ret[0] >>> 0;
220
+ RRegexFinalization.register(this, this.__wbg_ptr, this);
221
+ return this;
265
222
  }
266
223
  /**
267
- * Returns true if and only if there is a match for the regex in the
268
- * string given.
269
- *
270
- * It is recommended to use this method if all you need to do is test
271
- * a match, since the underlying matching engine may be able to do less
272
- * work.
273
- *
274
- * # Example
275
- *
276
- * Test if some text contains at least one word with exactly 13
277
- * Unicode word characters:
278
- *
279
- * ```typescript
280
- * import { RRegex } from "rregex"
281
- *
282
- * const text = "I categorically deny having triskaidekaphobia."
283
- * expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
284
- * ```
285
- *
286
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
287
- * @param {string} text - The string against which to match the regular expression
288
- * @return {boolean}
289
- */
224
+ * Returns true if and only if there is a match for the regex in the
225
+ * string given.
226
+ *
227
+ * It is recommended to use this method if all you need to do is test
228
+ * a match, since the underlying matching engine may be able to do less
229
+ * work.
230
+ *
231
+ * # Example
232
+ *
233
+ * Test if some text contains at least one word with exactly 13
234
+ * Unicode word characters:
235
+ *
236
+ * ```typescript
237
+ * import { RRegex } from "rregex"
238
+ *
239
+ * const text = "I categorically deny having triskaidekaphobia."
240
+ * expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
241
+ * ```
242
+ *
243
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
244
+ * @param {string} text - The string against which to match the regular expression
245
+ * @return {boolean}
246
+ */
290
247
  isMatch(text) {
291
248
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
292
249
  const len0 = WASM_VECTOR_LEN;
@@ -294,16 +251,16 @@ class RRegex {
294
251
  return ret !== 0;
295
252
  }
296
253
  /**
297
- * Returns the same as is_match, but starts the search at the given offset.
298
- * The significance of the starting point is that it takes the surrounding
299
- * context into consideration. For example, the `\A` anchor can only match
300
- * when `start == 0`.
301
- *
302
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
303
- * @param {string} text - The string against which to match the regular expression
304
- * @param {number} start - Zero-based index at which to start matching
305
- * @return {boolean}
306
- */
254
+ * Returns the same as is_match, but starts the search at the given offset.
255
+ * The significance of the starting point is that it takes the surrounding
256
+ * context into consideration. For example, the `\A` anchor can only match
257
+ * when `start == 0`.
258
+ *
259
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
260
+ * @param {string} text - The string against which to match the regular expression
261
+ * @param {number} start - Zero-based index at which to start matching
262
+ * @return {boolean}
263
+ */
307
264
  isMatchAt(text, start) {
308
265
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
309
266
  const len0 = WASM_VECTOR_LEN;
@@ -311,631 +268,532 @@ class RRegex {
311
268
  return ret !== 0;
312
269
  }
313
270
  /**
314
- * Returns the start and end byte range of the leftmost-first match in
315
- * `text`. If no match exists, then `undefined` is returned.
316
- *
317
- * Note that this should only be used if you want to discover the position
318
- * of the match. Testing the existence of a match is faster if you use
319
- * `isMatch`.
320
- *
321
- * # Example
322
- *
323
- * Find the start and end location of the first word with exactly 13
324
- * Unicode word characters:
325
- *
326
- * ```typescript
327
- * import { RRegex } from "rregex"
328
- *
329
- * const text = "I categorically deny having triskaidekaphobia."
330
- * const m = new RRegex("\\b\\w{13}\\b").find(text)
331
- * expect(m.start).toBe(2)
332
- * expect(m.end).toBe(15)
333
- * ```
334
- *
335
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
336
- * @param {string} text - The string against which to match the regular expression
337
- * @return {Match}
338
- */
271
+ * Returns the start and end byte range of the leftmost-first match in
272
+ * `text`. If no match exists, then `undefined` is returned.
273
+ *
274
+ * Note that this should only be used if you want to discover the position
275
+ * of the match. Testing the existence of a match is faster if you use
276
+ * `isMatch`.
277
+ *
278
+ * # Example
279
+ *
280
+ * Find the start and end location of the first word with exactly 13
281
+ * Unicode word characters:
282
+ *
283
+ * ```typescript
284
+ * import { RRegex } from "rregex"
285
+ *
286
+ * const text = "I categorically deny having triskaidekaphobia."
287
+ * const m = new RRegex("\\b\\w{13}\\b").find(text)
288
+ * expect(m.start).toBe(2)
289
+ * expect(m.end).toBe(15)
290
+ * ```
291
+ *
292
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
293
+ * @param {string} text - The string against which to match the regular expression
294
+ * @return {Match}
295
+ */
339
296
  find(text) {
340
- try {
341
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
342
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
343
- const len0 = WASM_VECTOR_LEN;
344
- wasm.rregex_find(retptr, this.__wbg_ptr, ptr0, len0);
345
- var r0 = getInt32Memory0()[retptr / 4 + 0];
346
- var r1 = getInt32Memory0()[retptr / 4 + 1];
347
- var r2 = getInt32Memory0()[retptr / 4 + 2];
348
- if (r2) {
349
- throw takeObject(r1);
350
- }
351
- return takeObject(r0);
352
- } finally {
353
- wasm.__wbindgen_add_to_stack_pointer(16);
297
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
298
+ const len0 = WASM_VECTOR_LEN;
299
+ const ret = wasm.rregex_find(this.__wbg_ptr, ptr0, len0);
300
+ if (ret[2]) {
301
+ throw takeFromExternrefTable0(ret[1]);
354
302
  }
303
+ return takeFromExternrefTable0(ret[0]);
355
304
  }
356
305
  /**
357
- * Returns the same as find, but starts the search at the given
358
- * offset.
359
- *
360
- * The significance of the starting point is that it takes the surrounding
361
- * context into consideration. For example, the `\A` anchor can only
362
- * match when `start == 0`.
363
- *
364
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
365
- * @param {string} text - The string against which to match the regular expression
366
- * @param {number} start - Zero-based index at which to start matching
367
- * @returns {Match}
368
- */
306
+ * Returns the same as find, but starts the search at the given
307
+ * offset.
308
+ *
309
+ * The significance of the starting point is that it takes the surrounding
310
+ * context into consideration. For example, the `\A` anchor can only
311
+ * match when `start == 0`.
312
+ *
313
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
314
+ * @param {string} text - The string against which to match the regular expression
315
+ * @param {number} start - Zero-based index at which to start matching
316
+ * @returns {Match}
317
+ */
369
318
  findAt(text, start) {
370
- try {
371
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
372
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
373
- const len0 = WASM_VECTOR_LEN;
374
- wasm.rregex_findAt(retptr, this.__wbg_ptr, ptr0, len0, start);
375
- var r0 = getInt32Memory0()[retptr / 4 + 0];
376
- var r1 = getInt32Memory0()[retptr / 4 + 1];
377
- var r2 = getInt32Memory0()[retptr / 4 + 2];
378
- if (r2) {
379
- throw takeObject(r1);
380
- }
381
- return takeObject(r0);
382
- } finally {
383
- wasm.__wbindgen_add_to_stack_pointer(16);
319
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
320
+ const len0 = WASM_VECTOR_LEN;
321
+ const ret = wasm.rregex_findAt(this.__wbg_ptr, ptr0, len0, start);
322
+ if (ret[2]) {
323
+ throw takeFromExternrefTable0(ret[1]);
384
324
  }
325
+ return takeFromExternrefTable0(ret[0]);
385
326
  }
386
327
  /**
387
- * Returns an array for each successive non-overlapping match in `text``,
388
- * returning the start and end byte indices with respect to `text`.
389
- *
390
- * # Example
391
- *
392
- * Find the start and end location of every word with exactly 13 Unicode
393
- * word characters:
394
- *
395
- * ```typescript
396
- * import { RRegex } from "rregex"
397
- *
398
- * const text = "Retroactively relinquishing remunerations is reprehensible."
399
- * const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
400
- * ```
401
- *
402
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
403
- * @param {string} text - The string against which to match the regular expression
404
- * @returns {Match}
405
- */
328
+ * Returns an array for each successive non-overlapping match in `text``,
329
+ * returning the start and end byte indices with respect to `text`.
330
+ *
331
+ * # Example
332
+ *
333
+ * Find the start and end location of every word with exactly 13 Unicode
334
+ * word characters:
335
+ *
336
+ * ```typescript
337
+ * import { RRegex } from "rregex"
338
+ *
339
+ * const text = "Retroactively relinquishing remunerations is reprehensible."
340
+ * const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
341
+ * ```
342
+ *
343
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
344
+ * @param {string} text - The string against which to match the regular expression
345
+ * @returns {Match}
346
+ */
406
347
  findAll(text) {
407
- try {
408
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
409
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
410
- const len0 = WASM_VECTOR_LEN;
411
- wasm.rregex_findAll(retptr, this.__wbg_ptr, ptr0, len0);
412
- var r0 = getInt32Memory0()[retptr / 4 + 0];
413
- var r1 = getInt32Memory0()[retptr / 4 + 1];
414
- var r2 = getInt32Memory0()[retptr / 4 + 2];
415
- if (r2) {
416
- throw takeObject(r1);
417
- }
418
- return takeObject(r0);
419
- } finally {
420
- wasm.__wbindgen_add_to_stack_pointer(16);
348
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
349
+ const len0 = WASM_VECTOR_LEN;
350
+ const ret = wasm.rregex_findAll(this.__wbg_ptr, ptr0, len0);
351
+ if (ret[2]) {
352
+ throw takeFromExternrefTable0(ret[1]);
421
353
  }
354
+ return takeFromExternrefTable0(ret[0]);
422
355
  }
423
356
  /**
424
- * Returns a list of the capture names in this regex.
425
- *
426
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
427
- */
357
+ * Returns a list of the capture names in this regex.
358
+ *
359
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
360
+ */
428
361
  captureNames() {
429
- try {
430
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
431
- wasm.rregex_captureNames(retptr, this.__wbg_ptr);
432
- var r0 = getInt32Memory0()[retptr / 4 + 0];
433
- var r1 = getInt32Memory0()[retptr / 4 + 1];
434
- var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
435
- wasm.__wbindgen_free(r0, r1 * 4, 4);
436
- return v1;
437
- } finally {
438
- wasm.__wbindgen_add_to_stack_pointer(16);
439
- }
362
+ const ret = wasm.rregex_captureNames(this.__wbg_ptr);
363
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
364
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
365
+ return v1;
440
366
  }
441
367
  /**
442
- * Returns the capture groups corresponding to the leftmost-first
443
- * match in `text`. Capture group `0` always corresponds to the entire
444
- * match. If no match is found, then `undefined` is returned.
445
- *
446
- * You should only use `captures` if you need access to the location of
447
- * capturing group matches. Otherwise, `find` is faster for discovering
448
- * the location of the overall match.
449
- *
450
- * # Examples
451
- *
452
- * Say you have some text with movie names and their release years,
453
- * like "'Citizen Kane' (1941)". It'd be nice if we could search for text
454
- * looking like that, while also extracting the movie name and its release
455
- * year separately.
456
- *
457
- * ```typescript
458
- * import { RRegex } from "rregex"
459
- *
460
- * const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
461
- * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
462
- * const caps = re.captures(text)
463
- * expect(caps.get[1].value).toBe("Citizen Kane")
464
- * expect(caps.get[2].value).toBe("1941")
465
- * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
466
- * ```
467
- *
468
- * Note that the full match is at capture group `0`. Each subsequent
469
- * capture group is indexed by the order of its opening `(`.
470
- *
471
- * We can make this example a bit clearer by using *named* capture groups:
472
- *
473
- * ```typescript
474
- * import { RRegex } from "rregex"
475
- *
476
- * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
477
- * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
478
- * const caps = re.captures(text)
479
- * expect(caps.name["title"].value).toBe("Citizen Kane")
480
- * expect(caps.name["year"].value).toBe("1941")
481
- * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
482
- * ```
483
- *
484
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
485
- * @param {string} text - The string against which to match the regular expression
486
- * @returns {Captures|undefined}
487
- */
368
+ * Returns the capture groups corresponding to the leftmost-first
369
+ * match in `text`. Capture group `0` always corresponds to the entire
370
+ * match. If no match is found, then `undefined` is returned.
371
+ *
372
+ * You should only use `captures` if you need access to the location of
373
+ * capturing group matches. Otherwise, `find` is faster for discovering
374
+ * the location of the overall match.
375
+ *
376
+ * # Examples
377
+ *
378
+ * Say you have some text with movie names and their release years,
379
+ * like "'Citizen Kane' (1941)". It'd be nice if we could search for text
380
+ * looking like that, while also extracting the movie name and its release
381
+ * year separately.
382
+ *
383
+ * ```typescript
384
+ * import { RRegex } from "rregex"
385
+ *
386
+ * const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
387
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
388
+ * const caps = re.captures(text)
389
+ * expect(caps.get[1].value).toBe("Citizen Kane")
390
+ * expect(caps.get[2].value).toBe("1941")
391
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
392
+ * ```
393
+ *
394
+ * Note that the full match is at capture group `0`. Each subsequent
395
+ * capture group is indexed by the order of its opening `(`.
396
+ *
397
+ * We can make this example a bit clearer by using *named* capture groups:
398
+ *
399
+ * ```typescript
400
+ * import { RRegex } from "rregex"
401
+ *
402
+ * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
403
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
404
+ * const caps = re.captures(text)
405
+ * expect(caps.name["title"].value).toBe("Citizen Kane")
406
+ * expect(caps.name["year"].value).toBe("1941")
407
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
408
+ * ```
409
+ *
410
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
411
+ * @param {string} text - The string against which to match the regular expression
412
+ * @returns {Captures|undefined}
413
+ */
488
414
  captures(text) {
489
- try {
490
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
491
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
492
- const len0 = WASM_VECTOR_LEN;
493
- wasm.rregex_captures(retptr, this.__wbg_ptr, ptr0, len0);
494
- var r0 = getInt32Memory0()[retptr / 4 + 0];
495
- var r1 = getInt32Memory0()[retptr / 4 + 1];
496
- var r2 = getInt32Memory0()[retptr / 4 + 2];
497
- if (r2) {
498
- throw takeObject(r1);
499
- }
500
- return takeObject(r0);
501
- } finally {
502
- wasm.__wbindgen_add_to_stack_pointer(16);
415
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
416
+ const len0 = WASM_VECTOR_LEN;
417
+ const ret = wasm.rregex_captures(this.__wbg_ptr, ptr0, len0);
418
+ if (ret[2]) {
419
+ throw takeFromExternrefTable0(ret[1]);
503
420
  }
421
+ return takeFromExternrefTable0(ret[0]);
504
422
  }
505
423
  /**
506
- * Returns a list with all the non-overlapping capture groups matched
507
- * in `text`. This is operationally the same as `findAll`, except it
508
- * returns information about capturing group matches.
509
- *
510
- * # Example
511
- *
512
- * We can use this to find all movie titles and their release years in
513
- * some text, where the movie is formatted like "'Title' (xxxx)":
514
- *
515
- * ```typescript
516
- * import { RRegex } from "rregex"
517
- *
518
- * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
519
- * const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
520
- * for caps of re.captures_iter(text) {
521
- * console.log(
522
- * "Movie:", caps.name["title"].value, ","
523
- * "Released:", caps.name["year"].value
524
- * );
525
- * }
526
- * // Output:
527
- * // Movie: Citizen Kane, Released: 1941
528
- * // Movie: The Wizard of Oz, Released: 1939
529
- * // Movie: M, Released: 1931
530
- * ```
531
- *
532
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
533
- * @param {string} text - The string against which to match the regular expression
534
- * @returns {Captures[]}
535
- */
424
+ * Returns a list with all the non-overlapping capture groups matched
425
+ * in `text`. This is operationally the same as `findAll`, except it
426
+ * returns information about capturing group matches.
427
+ *
428
+ * # Example
429
+ *
430
+ * We can use this to find all movie titles and their release years in
431
+ * some text, where the movie is formatted like "'Title' (xxxx)":
432
+ *
433
+ * ```typescript
434
+ * import { RRegex } from "rregex"
435
+ *
436
+ * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
437
+ * const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
438
+ * for caps of re.captures_iter(text) {
439
+ * console.log(
440
+ * "Movie:", caps.name["title"].value, ","
441
+ * "Released:", caps.name["year"].value
442
+ * );
443
+ * }
444
+ * // Output:
445
+ * // Movie: Citizen Kane, Released: 1941
446
+ * // Movie: The Wizard of Oz, Released: 1939
447
+ * // Movie: M, Released: 1931
448
+ * ```
449
+ *
450
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
451
+ * @param {string} text - The string against which to match the regular expression
452
+ * @returns {Captures[]}
453
+ */
536
454
  capturesAll(text) {
537
- try {
538
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
539
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
540
- const len0 = WASM_VECTOR_LEN;
541
- wasm.rregex_capturesAll(retptr, this.__wbg_ptr, ptr0, len0);
542
- var r0 = getInt32Memory0()[retptr / 4 + 0];
543
- var r1 = getInt32Memory0()[retptr / 4 + 1];
544
- var r2 = getInt32Memory0()[retptr / 4 + 2];
545
- if (r2) {
546
- throw takeObject(r1);
547
- }
548
- return takeObject(r0);
549
- } finally {
550
- wasm.__wbindgen_add_to_stack_pointer(16);
455
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
456
+ const len0 = WASM_VECTOR_LEN;
457
+ const ret = wasm.rregex_capturesAll(this.__wbg_ptr, ptr0, len0);
458
+ if (ret[2]) {
459
+ throw takeFromExternrefTable0(ret[1]);
551
460
  }
461
+ return takeFromExternrefTable0(ret[0]);
552
462
  }
553
463
  /**
554
- * Returns the number of captures.
555
- *
556
- * This includes all named and unnamed groups, including the implicit
557
- * unnamed group that is always present and corresponds to the entire match.
558
- *
559
- * Since the implicit unnamed group is always included in this length, the
560
- * length returned is guaranteed to be greater than zero.
561
- *
562
- * ## Example
563
- *
564
- * ```typescript
565
- * import { RRegex } from "rregex"
566
- *
567
- * const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
568
- * expect(re1.capturesLength()).toEqual(4)
569
- *
570
- * const re2 = new RRegex("foo")
571
- * expect(re2.capturesLength()).toEqual(1)
572
- *
573
- * const re3 = new RRegex("(foo)")
574
- * expect(re3.capturesLength()).toEqual(2)
575
- *
576
- * const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
577
- * expect(re4.capturesLength()).toEqual(5)
578
- *
579
- * const re5 = new RRegex("[a&&b]")
580
- * expect(re5.capturesLength()).toEqual(1)
581
- * ```
582
- *
583
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
584
- * @returns {number}
585
- */
464
+ * Returns the number of captures.
465
+ *
466
+ * This includes all named and unnamed groups, including the implicit
467
+ * unnamed group that is always present and corresponds to the entire match.
468
+ *
469
+ * Since the implicit unnamed group is always included in this length, the
470
+ * length returned is guaranteed to be greater than zero.
471
+ *
472
+ * ## Example
473
+ *
474
+ * ```typescript
475
+ * import { RRegex } from "rregex"
476
+ *
477
+ * const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
478
+ * expect(re1.capturesLength()).toEqual(4)
479
+ *
480
+ * const re2 = new RRegex("foo")
481
+ * expect(re2.capturesLength()).toEqual(1)
482
+ *
483
+ * const re3 = new RRegex("(foo)")
484
+ * expect(re3.capturesLength()).toEqual(2)
485
+ *
486
+ * const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
487
+ * expect(re4.capturesLength()).toEqual(5)
488
+ *
489
+ * const re5 = new RRegex("[a&&b]")
490
+ * expect(re5.capturesLength()).toEqual(1)
491
+ * ```
492
+ *
493
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
494
+ * @returns {number}
495
+ */
586
496
  capturesLength() {
587
497
  const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
588
498
  return ret >>> 0;
589
499
  }
590
500
  /**
591
- * Replaces the leftmost-first match with the replacement provided.
592
- * The replacement can be a regular string (where `$N` and `$name` are
593
- * expanded to match capture groups) or a function that takes the matches'
594
- * `Captures` and returns the replaced string.
595
- *
596
- * If no match is found, then a copy of the string is returned unchanged.
597
- *
598
- * # Replacement string syntax
599
- *
600
- * All instances of `$name` in the replacement text is replaced with the
601
- * corresponding capture group `name`.
602
- *
603
- * `name` may be an integer corresponding to the index of the
604
- * capture group (counted by order of opening parenthesis where `0` is the
605
- * entire match) or it can be a name (consisting of letters, digits or
606
- * underscores) corresponding to a named capture group.
607
- *
608
- * If `name` isn't a valid capture group (whether the name doesn't exist
609
- * or isn't a valid index), then it is replaced with the empty string.
610
- *
611
- * The longest possible name is used. e.g., `$1a` looks up the capture
612
- * group named `1a` and not the capture group at index `1`. To exert more
613
- * precise control over the name, use braces, e.g., `${1}a`.
614
- *
615
- * To write a literal `$` use `$$`.
616
- *
617
- * # Examples
618
- *
619
- * Note that this function is polymorphic with respect to the replacement.
620
- * In typical usage, this can just be a normal string:
621
- *
622
- * ```typescript
623
- * import { RRegex } from "rregex"
624
- *
625
- * const re = new RRegex("[^01]+")
626
- * expect(re.replace("1078910", "").toBe("1010")
627
- * ```
628
- *
629
- * Here's the example using this expansion technique with named capture
630
- * groups:
631
- *
632
- * ```typescript
633
- * import { RRegex } from "rregex"
634
- *
635
- * const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
636
- * const result = re.replace("Springsteen, Bruce", "$first $last")
637
- * expect(result).toBe("Bruce Springsteen")
638
- * ```
639
- *
640
- * Note that using `$2` instead of `$first` or `$1` instead of `$last`
641
- * would produce the same result. To write a literal `$` use `$$`.
642
- *
643
- * Sometimes the replacement string requires use of curly braces to
644
- * delineate a capture group replacement and surrounding literal text.
645
- * For example, if we wanted to join two words together with an
646
- * underscore:
647
- *
648
- * ```typescript
649
- * import { RRegex } from "rregex"
650
- *
651
- * const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
652
- * const result = re.replace("deep fried", "${first}_$second")
653
- * expect(result).toBe("deep_fried")
654
- * ```
655
- *
656
- * Without the curly braces, the capture group name `first_` would be
657
- * used, and since it doesn't exist, it would be replaced with the empty
658
- * string.
659
- *
660
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
661
- * @param {string} text - The string against which to match the regular expression
662
- * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
663
- * @returns {string}
664
- */
501
+ * Replaces the leftmost-first match with the replacement provided.
502
+ * The replacement can be a regular string (where `$N` and `$name` are
503
+ * expanded to match capture groups) or a function that takes the matches'
504
+ * `Captures` and returns the replaced string.
505
+ *
506
+ * If no match is found, then a copy of the string is returned unchanged.
507
+ *
508
+ * # Replacement string syntax
509
+ *
510
+ * All instances of `$name` in the replacement text is replaced with the
511
+ * corresponding capture group `name`.
512
+ *
513
+ * `name` may be an integer corresponding to the index of the
514
+ * capture group (counted by order of opening parenthesis where `0` is the
515
+ * entire match) or it can be a name (consisting of letters, digits or
516
+ * underscores) corresponding to a named capture group.
517
+ *
518
+ * If `name` isn't a valid capture group (whether the name doesn't exist
519
+ * or isn't a valid index), then it is replaced with the empty string.
520
+ *
521
+ * The longest possible name is used. e.g., `$1a` looks up the capture
522
+ * group named `1a` and not the capture group at index `1`. To exert more
523
+ * precise control over the name, use braces, e.g., `${1}a`.
524
+ *
525
+ * To write a literal `$` use `$$`.
526
+ *
527
+ * # Examples
528
+ *
529
+ * Note that this function is polymorphic with respect to the replacement.
530
+ * In typical usage, this can just be a normal string:
531
+ *
532
+ * ```typescript
533
+ * import { RRegex } from "rregex"
534
+ *
535
+ * const re = new RRegex("[^01]+")
536
+ * expect(re.replace("1078910", "").toBe("1010")
537
+ * ```
538
+ *
539
+ * Here's the example using this expansion technique with named capture
540
+ * groups:
541
+ *
542
+ * ```typescript
543
+ * import { RRegex } from "rregex"
544
+ *
545
+ * const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
546
+ * const result = re.replace("Springsteen, Bruce", "$first $last")
547
+ * expect(result).toBe("Bruce Springsteen")
548
+ * ```
549
+ *
550
+ * Note that using `$2` instead of `$first` or `$1` instead of `$last`
551
+ * would produce the same result. To write a literal `$` use `$$`.
552
+ *
553
+ * Sometimes the replacement string requires use of curly braces to
554
+ * delineate a capture group replacement and surrounding literal text.
555
+ * For example, if we wanted to join two words together with an
556
+ * underscore:
557
+ *
558
+ * ```typescript
559
+ * import { RRegex } from "rregex"
560
+ *
561
+ * const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
562
+ * const result = re.replace("deep fried", "${first}_$second")
563
+ * expect(result).toBe("deep_fried")
564
+ * ```
565
+ *
566
+ * Without the curly braces, the capture group name `first_` would be
567
+ * used, and since it doesn't exist, it would be replaced with the empty
568
+ * string.
569
+ *
570
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
571
+ * @param {string} text - The string against which to match the regular expression
572
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
573
+ * @returns {string}
574
+ */
665
575
  replace(text, rep) {
666
576
  let deferred3_0;
667
577
  let deferred3_1;
668
578
  try {
669
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
670
579
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
671
580
  const len0 = WASM_VECTOR_LEN;
672
581
  const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
673
582
  const len1 = WASM_VECTOR_LEN;
674
- wasm.rregex_replace(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
675
- var r0 = getInt32Memory0()[retptr / 4 + 0];
676
- var r1 = getInt32Memory0()[retptr / 4 + 1];
677
- deferred3_0 = r0;
678
- deferred3_1 = r1;
679
- return getStringFromWasm0(r0, r1);
583
+ const ret = wasm.rregex_replace(this.__wbg_ptr, ptr0, len0, ptr1, len1);
584
+ deferred3_0 = ret[0];
585
+ deferred3_1 = ret[1];
586
+ return getStringFromWasm0(ret[0], ret[1]);
680
587
  } finally {
681
- wasm.__wbindgen_add_to_stack_pointer(16);
682
588
  wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
683
589
  }
684
590
  }
685
591
  /**
686
- * Replaces at most `limit` non-overlapping matches in `text` with the
687
- * replacement provided. If `limit` is 0, then all non-overlapping matches
688
- * are replaced.
689
- *
690
- * See the documentation for `replace` for details on how to access
691
- * capturing group matches in the replacement string.
692
- *
693
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
694
- * @param {string} text - The string against which to match the regular expression
695
- * @param {number} limit - Max number of replacement
696
- * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
697
- * @returns {string}
698
- */
592
+ * Replaces at most `limit` non-overlapping matches in `text` with the
593
+ * replacement provided. If `limit` is 0, then all non-overlapping matches
594
+ * are replaced.
595
+ *
596
+ * See the documentation for `replace` for details on how to access
597
+ * capturing group matches in the replacement string.
598
+ *
599
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
600
+ * @param {string} text - The string against which to match the regular expression
601
+ * @param {number} limit - Max number of replacement
602
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
603
+ * @returns {string}
604
+ */
699
605
  replacen(text, limit, rep) {
700
606
  let deferred3_0;
701
607
  let deferred3_1;
702
608
  try {
703
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
704
609
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
705
610
  const len0 = WASM_VECTOR_LEN;
706
611
  const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
707
612
  const len1 = WASM_VECTOR_LEN;
708
- wasm.rregex_replacen(retptr, this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
709
- var r0 = getInt32Memory0()[retptr / 4 + 0];
710
- var r1 = getInt32Memory0()[retptr / 4 + 1];
711
- deferred3_0 = r0;
712
- deferred3_1 = r1;
713
- return getStringFromWasm0(r0, r1);
613
+ const ret = wasm.rregex_replacen(this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
614
+ deferred3_0 = ret[0];
615
+ deferred3_1 = ret[1];
616
+ return getStringFromWasm0(ret[0], ret[1]);
714
617
  } finally {
715
- wasm.__wbindgen_add_to_stack_pointer(16);
716
618
  wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
717
619
  }
718
620
  }
719
621
  /**
720
- * Replaces all non-overlapping matches in `text` with the replacement
721
- * provided. This is the same as calling `replacen` with `limit` set to
722
- * `0`.
723
- *
724
- * See the documentation for `replace` for details on how to access
725
- * capturing group matches in the replacement string.
726
- *
727
- * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
728
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
729
- * @param {string} text - The string against which to match the regular expression
730
- * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
731
- * @returns {string}
732
- */
622
+ * Replaces all non-overlapping matches in `text` with the replacement
623
+ * provided. This is the same as calling `replacen` with `limit` set to
624
+ * `0`.
625
+ *
626
+ * See the documentation for `replace` for details on how to access
627
+ * capturing group matches in the replacement string.
628
+ *
629
+ * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
630
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
631
+ * @param {string} text - The string against which to match the regular expression
632
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
633
+ * @returns {string}
634
+ */
733
635
  replaceAll(text, rep) {
734
636
  let deferred3_0;
735
637
  let deferred3_1;
736
638
  try {
737
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
738
639
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
739
640
  const len0 = WASM_VECTOR_LEN;
740
641
  const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
741
642
  const len1 = WASM_VECTOR_LEN;
742
- wasm.rregex_replaceAll(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
743
- var r0 = getInt32Memory0()[retptr / 4 + 0];
744
- var r1 = getInt32Memory0()[retptr / 4 + 1];
745
- deferred3_0 = r0;
746
- deferred3_1 = r1;
747
- return getStringFromWasm0(r0, r1);
643
+ const ret = wasm.rregex_replaceAll(this.__wbg_ptr, ptr0, len0, ptr1, len1);
644
+ deferred3_0 = ret[0];
645
+ deferred3_1 = ret[1];
646
+ return getStringFromWasm0(ret[0], ret[1]);
748
647
  } finally {
749
- wasm.__wbindgen_add_to_stack_pointer(16);
750
648
  wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
751
649
  }
752
650
  }
753
651
  /**
754
- * Returns an iterator of substrings of `text` delimited by a match of the
755
- * regular expression. Namely, each element of the iterator corresponds to
756
- * text that *isn't* matched by the regular expression.
757
- *
758
- * This method will *not* copy the text given.
759
- *
760
- * # Example
761
- *
762
- * To split a string delimited by arbitrary amounts of spaces or tabs:
763
- *
764
- * ```typescript
765
- * import { RRegex } from "rregex"
766
- *
767
- * const re = new RRegex(r"[ \\t]+")
768
- * const fields = re.split("a b \t c\td e")
769
- * expect(fields).toEqual(["a", "b", "c", "d", "e"])
770
- * ```
771
- *
772
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
773
- * @param {string} text - The string against which to match the regular expression
774
- * @returns {string[]}
775
- */
652
+ * Returns an iterator of substrings of `text` delimited by a match of the
653
+ * regular expression. Namely, each element of the iterator corresponds to
654
+ * text that *isn't* matched by the regular expression.
655
+ *
656
+ * This method will *not* copy the text given.
657
+ *
658
+ * # Example
659
+ *
660
+ * To split a string delimited by arbitrary amounts of spaces or tabs:
661
+ *
662
+ * ```typescript
663
+ * import { RRegex } from "rregex"
664
+ *
665
+ * const re = new RRegex(r"[ \\t]+")
666
+ * const fields = re.split("a b \t c\td e")
667
+ * expect(fields).toEqual(["a", "b", "c", "d", "e"])
668
+ * ```
669
+ *
670
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
671
+ * @param {string} text - The string against which to match the regular expression
672
+ * @returns {string[]}
673
+ */
776
674
  split(text) {
777
- try {
778
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
779
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
780
- const len0 = WASM_VECTOR_LEN;
781
- wasm.rregex_split(retptr, this.__wbg_ptr, ptr0, len0);
782
- var r0 = getInt32Memory0()[retptr / 4 + 0];
783
- var r1 = getInt32Memory0()[retptr / 4 + 1];
784
- var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
785
- wasm.__wbindgen_free(r0, r1 * 4, 4);
786
- return v2;
787
- } finally {
788
- wasm.__wbindgen_add_to_stack_pointer(16);
789
- }
675
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
676
+ const len0 = WASM_VECTOR_LEN;
677
+ const ret = wasm.rregex_split(this.__wbg_ptr, ptr0, len0);
678
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
679
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
680
+ return v2;
790
681
  }
791
682
  /**
792
- * Returns an iterator of at most `limit` substrings of `text` delimited
793
- * by a match of the regular expression. (A `limit` of `0` will return no
794
- * substrings.) Namely, each element of the iterator corresponds to text
795
- * that *isn't* matched by the regular expression. The remainder of the
796
- * string that is not split will be the last element in the iterator.
797
- *
798
- * This method will *not* copy the text given.
799
- *
800
- * # Example
801
- *
802
- * Get the first two words in some text:
803
- *
804
- * ```typescript
805
- * import { RRegex } from "rregex"
806
- *
807
- * const re = new RRegex(r"\\W+")
808
- * const fields = re.splitn("Hey! How are you?", 3)
809
- * expect(fields).toEqual(["Hey", "How", "are you?"])
810
- * ```
811
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
812
- * @param {string} text - The string against which to match the regular expression
813
- * @param {number} limit - Max number result elements
814
- * @returns {string[]}
815
- */
683
+ * Returns an iterator of at most `limit` substrings of `text` delimited
684
+ * by a match of the regular expression. (A `limit` of `0` will return no
685
+ * substrings.) Namely, each element of the iterator corresponds to text
686
+ * that *isn't* matched by the regular expression. The remainder of the
687
+ * string that is not split will be the last element in the iterator.
688
+ *
689
+ * This method will *not* copy the text given.
690
+ *
691
+ * # Example
692
+ *
693
+ * Get the first two words in some text:
694
+ *
695
+ * ```typescript
696
+ * import { RRegex } from "rregex"
697
+ *
698
+ * const re = new RRegex(r"\\W+")
699
+ * const fields = re.splitn("Hey! How are you?", 3)
700
+ * expect(fields).toEqual(["Hey", "How", "are you?"])
701
+ * ```
702
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
703
+ * @param {string} text - The string against which to match the regular expression
704
+ * @param {number} limit - Max number result elements
705
+ * @returns {string[]}
706
+ */
816
707
  splitn(text, limit) {
817
- try {
818
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
819
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
820
- const len0 = WASM_VECTOR_LEN;
821
- wasm.rregex_splitn(retptr, this.__wbg_ptr, ptr0, len0, limit);
822
- var r0 = getInt32Memory0()[retptr / 4 + 0];
823
- var r1 = getInt32Memory0()[retptr / 4 + 1];
824
- var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
825
- wasm.__wbindgen_free(r0, r1 * 4, 4);
826
- return v2;
827
- } finally {
828
- wasm.__wbindgen_add_to_stack_pointer(16);
829
- }
708
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
709
+ const len0 = WASM_VECTOR_LEN;
710
+ const ret = wasm.rregex_splitn(this.__wbg_ptr, ptr0, len0, limit);
711
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
712
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
713
+ return v2;
830
714
  }
831
715
  /**
832
- * Returns the end location of a match in the text given.
833
- *
834
- * This method may have the same performance characteristics as
835
- * `isMatch`, except it provides an end location for a match. In
836
- * particular, the location returned *may be shorter* than the proper end
837
- * of the leftmost-first match that you would find via `Regex.find`.
838
- *
839
- * Note that it is not guaranteed that this routine finds the shortest or
840
- * "earliest" possible match. Instead, the main idea of this API is that
841
- * it returns the offset at the point at which the internal regex engine
842
- * has determined that a match has occurred. This may vary depending on
843
- * which internal regex engine is used, and thus, the offset itself may
844
- * change.
845
- *
846
- * # Example
847
- *
848
- * Typically, `a+` would match the entire first sequence of `a` in some
849
- * text, but `shortest_match` can give up as soon as it sees the first
850
- * `a`.
851
- *
852
- * ```typescript
853
- * import { RRegex } from "rregex"
854
- *
855
- * const text = "aaaaa"
856
- * const = new RRegex("a+").shortest_match(text)
857
- * expect(pos).toBe(1)
858
- * ```
859
- *
860
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
861
- * @param {string} text - The string against which to match the regular expression
862
- * @returns {number|undefined}
863
- */
716
+ * Returns the end location of a match in the text given.
717
+ *
718
+ * This method may have the same performance characteristics as
719
+ * `isMatch`, except it provides an end location for a match. In
720
+ * particular, the location returned *may be shorter* than the proper end
721
+ * of the leftmost-first match that you would find via `Regex.find`.
722
+ *
723
+ * Note that it is not guaranteed that this routine finds the shortest or
724
+ * "earliest" possible match. Instead, the main idea of this API is that
725
+ * it returns the offset at the point at which the internal regex engine
726
+ * has determined that a match has occurred. This may vary depending on
727
+ * which internal regex engine is used, and thus, the offset itself may
728
+ * change.
729
+ *
730
+ * # Example
731
+ *
732
+ * Typically, `a+` would match the entire first sequence of `a` in some
733
+ * text, but `shortest_match` can give up as soon as it sees the first
734
+ * `a`.
735
+ *
736
+ * ```typescript
737
+ * import { RRegex } from "rregex"
738
+ *
739
+ * const text = "aaaaa"
740
+ * const = new RRegex("a+").shortest_match(text)
741
+ * expect(pos).toBe(1)
742
+ * ```
743
+ *
744
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
745
+ * @param {string} text - The string against which to match the regular expression
746
+ * @returns {number|undefined}
747
+ */
864
748
  shortestMatch(text) {
865
- try {
866
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
867
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
868
- const len0 = WASM_VECTOR_LEN;
869
- wasm.rregex_shortestMatch(retptr, this.__wbg_ptr, ptr0, len0);
870
- var r0 = getInt32Memory0()[retptr / 4 + 0];
871
- var r1 = getInt32Memory0()[retptr / 4 + 1];
872
- return r0 === 0 ? undefined : r1 >>> 0;
873
- } finally {
874
- wasm.__wbindgen_add_to_stack_pointer(16);
875
- }
749
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
750
+ const len0 = WASM_VECTOR_LEN;
751
+ const ret = wasm.rregex_shortestMatch(this.__wbg_ptr, ptr0, len0);
752
+ return ret === 0x100000001 ? undefined : ret;
876
753
  }
877
754
  /**
878
- * Returns the same as `shortest_match`, but starts the search at the
879
- * given offset.
880
- *
881
- * The significance of the starting point is that it takes the surrounding
882
- * context into consideration. For example, the `\A` anchor can only match
883
- * when `start == 0`.
884
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
885
- * @param {string} text - The string against which to match the regular expression
886
- * @param {number} start - Zero-based index at which to start matching
887
- * @returns {number|undefined}
888
- */
755
+ * Returns the same as `shortest_match`, but starts the search at the
756
+ * given offset.
757
+ *
758
+ * The significance of the starting point is that it takes the surrounding
759
+ * context into consideration. For example, the `\A` anchor can only match
760
+ * when `start == 0`.
761
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
762
+ * @param {string} text - The string against which to match the regular expression
763
+ * @param {number} start - Zero-based index at which to start matching
764
+ * @returns {number|undefined}
765
+ */
889
766
  shortestMatchAt(text, start) {
890
- try {
891
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
892
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
893
- const len0 = WASM_VECTOR_LEN;
894
- wasm.rregex_shortestMatchAt(retptr, this.__wbg_ptr, ptr0, len0, start);
895
- var r0 = getInt32Memory0()[retptr / 4 + 0];
896
- var r1 = getInt32Memory0()[retptr / 4 + 1];
897
- return r0 === 0 ? undefined : r1 >>> 0;
898
- } finally {
899
- wasm.__wbindgen_add_to_stack_pointer(16);
900
- }
767
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
768
+ const len0 = WASM_VECTOR_LEN;
769
+ const ret = wasm.rregex_shortestMatchAt(this.__wbg_ptr, ptr0, len0, start);
770
+ return ret === 0x100000001 ? undefined : ret;
901
771
  }
902
772
  /**
903
- * Returns the regular expression into a high level intermediate
904
- * representation.
905
- * @returns {any}
906
- */
773
+ * Returns the regular expression into a high level intermediate
774
+ * representation.
775
+ * @returns {any}
776
+ */
907
777
  syntax() {
908
- try {
909
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
910
- wasm.rregex_syntax(retptr, this.__wbg_ptr);
911
- var r0 = getInt32Memory0()[retptr / 4 + 0];
912
- var r1 = getInt32Memory0()[retptr / 4 + 1];
913
- var r2 = getInt32Memory0()[retptr / 4 + 2];
914
- if (r2) {
915
- throw takeObject(r1);
916
- }
917
- return takeObject(r0);
918
- } finally {
919
- wasm.__wbindgen_add_to_stack_pointer(16);
778
+ const ret = wasm.rregex_syntax(this.__wbg_ptr);
779
+ if (ret[2]) {
780
+ throw takeFromExternrefTable0(ret[1]);
920
781
  }
782
+ return takeFromExternrefTable0(ret[0]);
921
783
  }
922
784
  /**
923
- * Returns a string representing the regular expression
924
- * @returns {string}
925
- */
785
+ * Returns a string representing the regular expression
786
+ * @returns {string}
787
+ */
926
788
  toString() {
927
789
  let deferred1_0;
928
790
  let deferred1_1;
929
791
  try {
930
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
931
- wasm.rregex_toString(retptr, this.__wbg_ptr);
932
- var r0 = getInt32Memory0()[retptr / 4 + 0];
933
- var r1 = getInt32Memory0()[retptr / 4 + 1];
934
- deferred1_0 = r0;
935
- deferred1_1 = r1;
936
- return getStringFromWasm0(r0, r1);
792
+ const ret = wasm.rregex_toString(this.__wbg_ptr);
793
+ deferred1_0 = ret[0];
794
+ deferred1_1 = ret[1];
795
+ return getStringFromWasm0(ret[0], ret[1]);
937
796
  } finally {
938
- wasm.__wbindgen_add_to_stack_pointer(16);
939
797
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
940
798
  }
941
799
  }
@@ -944,19 +802,19 @@ module.exports.RRegex = RRegex;
944
802
 
945
803
  const RRegexSetFinalization = (typeof FinalizationRegistry === 'undefined')
946
804
  ? { register: () => {}, unregister: () => {} }
947
- : new FinalizationRegistry(ptr => wasm.__wbg_rregexset_free(ptr >>> 0));
805
+ : new FinalizationRegistry(ptr => wasm.__wbg_rregexset_free(ptr >>> 0, 1));
948
806
  /**
949
- * Match multiple (possibly overlapping) regular expressions in a single scan.
950
- * A regex set corresponds to the union of two or more regular expressions.
951
- *
952
- * That is, a regex set will match text where at least one of its constituent
953
- * regular expressions matches. A regex set as its formulated here provides a
954
- * touch more power: it will also report which regular expressions in the set match.
955
- * Indeed, this is the key difference between regex sets and a single `Regex`
956
- * with many alternates, since only one alternate can match at a time.
957
- *
958
- * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
959
- */
807
+ * Match multiple (possibly overlapping) regular expressions in a single scan.
808
+ * A regex set corresponds to the union of two or more regular expressions.
809
+ *
810
+ * That is, a regex set will match text where at least one of its constituent
811
+ * regular expressions matches. A regex set as its formulated here provides a
812
+ * touch more power: it will also report which regular expressions in the set match.
813
+ * Indeed, this is the key difference between regex sets and a single `Regex`
814
+ * with many alternates, since only one alternate can match at a time.
815
+ *
816
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.empty
817
+ */
960
818
  class RRegexSet {
961
819
 
962
820
  __destroy_into_raw() {
@@ -968,74 +826,66 @@ class RRegexSet {
968
826
 
969
827
  free() {
970
828
  const ptr = this.__destroy_into_raw();
971
- wasm.__wbg_rregexset_free(ptr);
829
+ wasm.__wbg_rregexset_free(ptr, 0);
972
830
  }
973
831
  /**
974
- * Create a new regex set with the given regular expressions.
975
- *
976
- * This takes an of strings, if any item in the list is not a valid regular
977
- * expressions, then an error is returned.
978
- *
979
- * # Example
980
- *
981
- * Create a new regex set from an iterator of strings:
982
- *
983
- * ```typescript
984
- * import { RegexSet } from "rregex"
985
- *
986
- * const set = new RegexSet(["\\w+", "\\d+"])
987
- * expect(set.is_match("foo")).toBe(true)
988
- * ```
989
- * @param {Array<any>} list
990
- */
832
+ * Create a new regex set with the given regular expressions.
833
+ *
834
+ * This takes an of strings, if any item in the list is not a valid regular
835
+ * expressions, then an error is returned.
836
+ *
837
+ * # Example
838
+ *
839
+ * Create a new regex set from an iterator of strings:
840
+ *
841
+ * ```typescript
842
+ * import { RegexSet } from "rregex"
843
+ *
844
+ * const set = new RegexSet(["\\w+", "\\d+"])
845
+ * expect(set.is_match("foo")).toBe(true)
846
+ * ```
847
+ * @param {Array<any>} list
848
+ */
991
849
  constructor(list) {
992
- try {
993
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
994
- wasm.rregexset_new(retptr, addBorrowedObject(list));
995
- var r0 = getInt32Memory0()[retptr / 4 + 0];
996
- var r1 = getInt32Memory0()[retptr / 4 + 1];
997
- var r2 = getInt32Memory0()[retptr / 4 + 2];
998
- if (r2) {
999
- throw takeObject(r1);
1000
- }
1001
- this.__wbg_ptr = r0 >>> 0;
1002
- return this;
1003
- } finally {
1004
- wasm.__wbindgen_add_to_stack_pointer(16);
1005
- heap[stack_pointer++] = undefined;
850
+ const ret = wasm.rregexset_new(list);
851
+ if (ret[2]) {
852
+ throw takeFromExternrefTable0(ret[1]);
1006
853
  }
854
+ this.__wbg_ptr = ret[0] >>> 0;
855
+ RRegexSetFinalization.register(this, this.__wbg_ptr, this);
856
+ return this;
1007
857
  }
1008
858
  /**
1009
- * Returns true if and only if one of the regexes in this set matches
1010
- * the text given.
1011
- *
1012
- * This method should be preferred if you only need to test whether any
1013
- * of the regexes in the set should match, but don't care about *which*
1014
- * regexes matched. This is because the underlying matching engine will
1015
- * quit immediately after seeing the first match instead of continuing to
1016
- * find all matches.
1017
- *
1018
- * Note that as with searches using `Regex`, the expression is unanchored
1019
- * by default. That is, if the regex does not start with `^` or `\A`, or
1020
- * end with `$` or `\z`, then it is permitted to match anywhere in the
1021
- * text.
1022
- *
1023
- * # Example
1024
- *
1025
- * Tests whether a set matches some text:
1026
- *
1027
- * ```typescript
1028
- * import { RegexSet } from "rregex"
1029
- *
1030
- * const set = new RegexSet(["\\w+", "\\d+"])
1031
- * expect(set.is_match("foo")).toBe(true)
1032
- * expect(!set.is_match("☃")).toBe(false)
1033
- * ```
1034
- *
1035
- * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
1036
- * @param {string} text - The string against which to match the regular expression
1037
- * @return {boolean}
1038
- */
859
+ * Returns true if and only if one of the regexes in this set matches
860
+ * the text given.
861
+ *
862
+ * This method should be preferred if you only need to test whether any
863
+ * of the regexes in the set should match, but don't care about *which*
864
+ * regexes matched. This is because the underlying matching engine will
865
+ * quit immediately after seeing the first match instead of continuing to
866
+ * find all matches.
867
+ *
868
+ * Note that as with searches using `Regex`, the expression is unanchored
869
+ * by default. That is, if the regex does not start with `^` or `\A`, or
870
+ * end with `$` or `\z`, then it is permitted to match anywhere in the
871
+ * text.
872
+ *
873
+ * # Example
874
+ *
875
+ * Tests whether a set matches some text:
876
+ *
877
+ * ```typescript
878
+ * import { RegexSet } from "rregex"
879
+ *
880
+ * const set = new RegexSet(["\\w+", "\\d+"])
881
+ * expect(set.is_match("foo")).toBe(true)
882
+ * expect(!set.is_match("☃")).toBe(false)
883
+ * ```
884
+ *
885
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
886
+ * @param {string} text - The string against which to match the regular expression
887
+ * @return {boolean}
888
+ */
1039
889
  isMatch(text) {
1040
890
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1041
891
  const len0 = WASM_VECTOR_LEN;
@@ -1043,171 +893,166 @@ class RRegexSet {
1043
893
  return ret !== 0;
1044
894
  }
1045
895
  /**
1046
- * Returns the set of regular expressions that match in the given text.
1047
- *
1048
- * The set returned contains the index of each regular expression that
1049
- * matches in the given text. The index is in correspondence with the
1050
- * order of regular expressions given to `RegexSet`'s constructor.
1051
- *
1052
- * The set can also be used to iterate over the matched indices.
1053
- *
1054
- * Note that as with searches using `Regex`, the expression is unanchored
1055
- * by default. That is, if the regex does not start with `^` or `\A`, or
1056
- * end with `$` or `\z`, then it is permitted to match anywhere in the
1057
- * text.
1058
- *
1059
- * # Example
1060
- *
1061
- * Tests which regular expressions match the given text:
1062
- *
1063
- * ```typescript
1064
- * import { RegexSet } from "rregex"
1065
- *
1066
- * const set = new RegexSet([
1067
- * "\\w+",
1068
- * "\\d+",
1069
- * "\\pL+",
1070
- * "foo",
1071
- * "bar",
1072
- * "barfoo",
1073
- * "foobar",
1074
- * ])
1075
- * const matches = set.matches("foobar")
1076
- * expect(matches).toBe([0, 2, 3, 4, 6])
1077
- * ```
1078
- *
1079
- * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
1080
- * @param {string} text - The string against which to match the regular expression
1081
- * @return {number[]}
1082
- */
896
+ * Returns the set of regular expressions that match in the given text.
897
+ *
898
+ * The set returned contains the index of each regular expression that
899
+ * matches in the given text. The index is in correspondence with the
900
+ * order of regular expressions given to `RegexSet`'s constructor.
901
+ *
902
+ * The set can also be used to iterate over the matched indices.
903
+ *
904
+ * Note that as with searches using `Regex`, the expression is unanchored
905
+ * by default. That is, if the regex does not start with `^` or `\A`, or
906
+ * end with `$` or `\z`, then it is permitted to match anywhere in the
907
+ * text.
908
+ *
909
+ * # Example
910
+ *
911
+ * Tests which regular expressions match the given text:
912
+ *
913
+ * ```typescript
914
+ * import { RegexSet } from "rregex"
915
+ *
916
+ * const set = new RegexSet([
917
+ * "\\w+",
918
+ * "\\d+",
919
+ * "\\pL+",
920
+ * "foo",
921
+ * "bar",
922
+ * "barfoo",
923
+ * "foobar",
924
+ * ])
925
+ * const matches = set.matches("foobar")
926
+ * expect(matches).toBe([0, 2, 3, 4, 6])
927
+ * ```
928
+ *
929
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
930
+ * @param {string} text - The string against which to match the regular expression
931
+ * @return {number[]}
932
+ */
1083
933
  matches(text) {
1084
- try {
1085
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1086
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1087
- const len0 = WASM_VECTOR_LEN;
1088
- wasm.rregexset_matches(retptr, this.__wbg_ptr, ptr0, len0);
1089
- var r0 = getInt32Memory0()[retptr / 4 + 0];
1090
- var r1 = getInt32Memory0()[retptr / 4 + 1];
1091
- var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
1092
- wasm.__wbindgen_free(r0, r1 * 4, 4);
1093
- return v2;
1094
- } finally {
1095
- wasm.__wbindgen_add_to_stack_pointer(16);
1096
- }
934
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
935
+ const len0 = WASM_VECTOR_LEN;
936
+ const ret = wasm.rregexset_matches(this.__wbg_ptr, ptr0, len0);
937
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
938
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
939
+ return v2;
1097
940
  }
1098
941
  }
1099
942
  module.exports.RRegexSet = RRegexSet;
1100
943
 
1101
- module.exports.__wbindgen_string_new = function(arg0, arg1) {
1102
- const ret = getStringFromWasm0(arg0, arg1);
1103
- return addHeapObject(ret);
944
+ module.exports.__wbg_buffer_61b7ce01341d7f88 = function(arg0) {
945
+ const ret = arg0.buffer;
946
+ return ret;
1104
947
  };
1105
948
 
1106
- module.exports.__wbindgen_number_new = function(arg0) {
1107
- const ret = arg0;
1108
- return addHeapObject(ret);
1109
- };
949
+ module.exports.__wbg_fromCodePoint_ef89154c4db48bdf = function() { return handleError(function (arg0) {
950
+ const ret = String.fromCodePoint(arg0 >>> 0);
951
+ return ret;
952
+ }, arguments) };
1110
953
 
1111
- module.exports.__wbindgen_object_drop_ref = function(arg0) {
1112
- takeObject(arg0);
954
+ module.exports.__wbg_from_d68eaa96dba25449 = function(arg0) {
955
+ const ret = Array.from(arg0);
956
+ return ret;
1113
957
  };
1114
958
 
1115
- module.exports.__wbindgen_string_get = function(arg0, arg1) {
1116
- const obj = getObject(arg1);
1117
- const ret = typeof(obj) === 'string' ? obj : undefined;
1118
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1119
- var len1 = WASM_VECTOR_LEN;
1120
- getInt32Memory0()[arg0 / 4 + 1] = len1;
1121
- getInt32Memory0()[arg0 / 4 + 0] = ptr1;
959
+ module.exports.__wbg_get_9aa3dff3f0266054 = function(arg0, arg1) {
960
+ const ret = arg0[arg1 >>> 0];
961
+ return ret;
1122
962
  };
1123
963
 
1124
- module.exports.__wbindgen_error_new = function(arg0, arg1) {
1125
- const ret = new Error(getStringFromWasm0(arg0, arg1));
1126
- return addHeapObject(ret);
964
+ module.exports.__wbg_length_d65cf0786bfc5739 = function(arg0) {
965
+ const ret = arg0.length;
966
+ return ret;
1127
967
  };
1128
968
 
1129
- module.exports.__wbindgen_bigint_from_u64 = function(arg0) {
1130
- const ret = BigInt.asUintN(64, arg0);
1131
- return addHeapObject(ret);
969
+ module.exports.__wbg_new_254fa9eac11932ae = function() {
970
+ const ret = new Array();
971
+ return ret;
1132
972
  };
1133
973
 
1134
- module.exports.__wbindgen_object_clone_ref = function(arg0) {
1135
- const ret = getObject(arg0);
1136
- return addHeapObject(ret);
974
+ module.exports.__wbg_new_3ff5b33b1ce712df = function(arg0) {
975
+ const ret = new Uint8Array(arg0);
976
+ return ret;
1137
977
  };
1138
978
 
1139
- module.exports.__wbg_set_f975102236d3c502 = function(arg0, arg1, arg2) {
1140
- getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
979
+ module.exports.__wbg_new_688846f374351c92 = function() {
980
+ const ret = new Object();
981
+ return ret;
1141
982
  };
1142
983
 
1143
- module.exports.__wbg_get_bd8e338fbd5f5cc8 = function(arg0, arg1) {
1144
- const ret = getObject(arg0)[arg1 >>> 0];
1145
- return addHeapObject(ret);
984
+ module.exports.__wbg_newwithbyteoffsetandlength_ba35896968751d91 = function(arg0, arg1, arg2) {
985
+ const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
986
+ return ret;
1146
987
  };
1147
988
 
1148
- module.exports.__wbg_length_cd7af8117672b8b8 = function(arg0) {
1149
- const ret = getObject(arg0).length;
989
+ module.exports.__wbg_push_6edad0df4b546b2c = function(arg0, arg1) {
990
+ const ret = arg0.push(arg1);
1150
991
  return ret;
1151
992
  };
1152
993
 
1153
- module.exports.__wbg_new_16b304a2cfa7ff4a = function() {
1154
- const ret = new Array();
1155
- return addHeapObject(ret);
994
+ module.exports.__wbg_set_1d80752d0d5f0b21 = function(arg0, arg1, arg2) {
995
+ arg0[arg1 >>> 0] = arg2;
1156
996
  };
1157
997
 
1158
- module.exports.__wbg_new_72fb9a18b5ae2624 = function() {
1159
- const ret = new Object();
1160
- return addHeapObject(ret);
998
+ module.exports.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
999
+ arg0[arg1] = arg2;
1161
1000
  };
1162
1001
 
1163
- module.exports.__wbg_set_d4638f722068f043 = function(arg0, arg1, arg2) {
1164
- getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
1165
- };
1002
+ module.exports.__wbg_set_4e647025551483bd = function() { return handleError(function (arg0, arg1, arg2) {
1003
+ const ret = Reflect.set(arg0, arg1, arg2);
1004
+ return ret;
1005
+ }, arguments) };
1166
1006
 
1167
- module.exports.__wbg_from_89e3fc3ba5e6fb48 = function(arg0) {
1168
- const ret = Array.from(getObject(arg0));
1169
- return addHeapObject(ret);
1007
+ module.exports.__wbindgen_bigint_from_u64 = function(arg0) {
1008
+ const ret = BigInt.asUintN(64, arg0);
1009
+ return ret;
1170
1010
  };
1171
1011
 
1172
- module.exports.__wbg_push_a5b05aedc7234f9f = function(arg0, arg1) {
1173
- const ret = getObject(arg0).push(getObject(arg1));
1012
+ module.exports.__wbindgen_error_new = function(arg0, arg1) {
1013
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
1174
1014
  return ret;
1175
1015
  };
1176
1016
 
1177
- module.exports.__wbg_fromCodePoint_cedd7612a2ff688f = function() { return handleError(function (arg0) {
1178
- const ret = String.fromCodePoint(arg0 >>> 0);
1179
- return addHeapObject(ret);
1180
- }, arguments) };
1017
+ module.exports.__wbindgen_init_externref_table = function() {
1018
+ const table = wasm.__wbindgen_export_2;
1019
+ const offset = table.grow(4);
1020
+ table.set(0, undefined);
1021
+ table.set(offset + 0, undefined);
1022
+ table.set(offset + 1, null);
1023
+ table.set(offset + 2, true);
1024
+ table.set(offset + 3, false);
1025
+ ;
1026
+ };
1181
1027
 
1182
- module.exports.__wbg_buffer_12d079cc21e14bdb = function(arg0) {
1183
- const ret = getObject(arg0).buffer;
1184
- return addHeapObject(ret);
1028
+ module.exports.__wbindgen_memory = function() {
1029
+ const ret = wasm.memory;
1030
+ return ret;
1185
1031
  };
1186
1032
 
1187
- module.exports.__wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb = function(arg0, arg1, arg2) {
1188
- const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
1189
- return addHeapObject(ret);
1033
+ module.exports.__wbindgen_number_new = function(arg0) {
1034
+ const ret = arg0;
1035
+ return ret;
1190
1036
  };
1191
1037
 
1192
- module.exports.__wbg_new_63b92bc8671ed464 = function(arg0) {
1193
- const ret = new Uint8Array(getObject(arg0));
1194
- return addHeapObject(ret);
1038
+ module.exports.__wbindgen_string_get = function(arg0, arg1) {
1039
+ const obj = arg1;
1040
+ const ret = typeof(obj) === 'string' ? obj : undefined;
1041
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1042
+ var len1 = WASM_VECTOR_LEN;
1043
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1044
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1195
1045
  };
1196
1046
 
1197
- module.exports.__wbg_set_1f9b04f170055d33 = function() { return handleError(function (arg0, arg1, arg2) {
1198
- const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
1047
+ module.exports.__wbindgen_string_new = function(arg0, arg1) {
1048
+ const ret = getStringFromWasm0(arg0, arg1);
1199
1049
  return ret;
1200
- }, arguments) };
1050
+ };
1201
1051
 
1202
1052
  module.exports.__wbindgen_throw = function(arg0, arg1) {
1203
1053
  throw new Error(getStringFromWasm0(arg0, arg1));
1204
1054
  };
1205
1055
 
1206
- module.exports.__wbindgen_memory = function() {
1207
- const ret = wasm.memory;
1208
- return addHeapObject(ret);
1209
- };
1210
-
1211
1056
  const path = require('path').join(__dirname, 'rregex.wasm');
1212
1057
  const bytes = require('fs').readFileSync(path);
1213
1058
 
@@ -1216,3 +1061,5 @@ const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
1216
1061
  wasm = wasmInstance.exports;
1217
1062
  module.exports.__wasm = wasm;
1218
1063
 
1064
+ wasm.__wbindgen_start();
1065
+