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