rregex 1.10.12 → 1.12.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
 
6
- const heap = new Array(128).fill(undefined);
7
-
8
- heap.push(undefined, null, true, false);
9
-
10
- let heap_next = heap.length;
11
-
12
- function addHeapObject(obj) {
13
- if (heap_next === heap.length) heap.push(heap.length + 1);
14
- const idx = heap_next;
15
- heap_next = heap[idx];
16
-
17
- heap[idx] = obj;
7
+ function addToExternrefTable0(obj) {
8
+ const idx = wasm.__externref_table_alloc();
9
+ wasm.__wbindgen_export_2.set(idx, obj);
18
10
  return idx;
19
11
  }
20
12
 
21
- function getObject(idx) { return heap[idx]; }
22
-
23
- function dropObject(idx) {
24
- if (idx < 132) return;
25
- heap[idx] = heap_next;
26
- heap_next = idx;
27
- }
28
-
29
- function takeObject(idx) {
30
- const ret = getObject(idx);
31
- dropObject(idx);
32
- return ret;
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
+ }
33
20
  }
34
21
 
35
22
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
36
23
 
37
24
  cachedTextDecoder.decode();
38
25
 
39
- let cachedUint8Memory0 = null;
26
+ let cachedUint8ArrayMemory0 = null;
40
27
 
41
- function getUint8Memory0() {
42
- if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
43
- cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
28
+ function getUint8ArrayMemory0() {
29
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
30
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
44
31
  }
45
- return cachedUint8Memory0;
32
+ return cachedUint8ArrayMemory0;
46
33
  }
47
34
 
48
35
  function getStringFromWasm0(ptr, len) {
49
36
  ptr = ptr >>> 0;
50
- return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
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,74 +200,19 @@ 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
- */
248
- 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);
264
- }
265
- }
266
- /**
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
- */
290
- isMatch(text) {
291
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
292
- const len0 = WASM_VECTOR_LEN;
293
- const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
294
- return ret !== 0;
295
- }
296
- /**
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
- */
206
+ * Returns the same as is_match, but starts the search at the given offset.
207
+ * The significance of the starting point is that it takes the surrounding
208
+ * context into consideration. For example, the `\A` anchor can only match
209
+ * when `start == 0`.
210
+ *
211
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
212
+ * @param {string} text - The string against which to match the regular expression
213
+ * @param {number} start - Zero-based index at which to start matching
214
+ * @return {boolean}
215
+ */
307
216
  isMatchAt(text, start) {
308
217
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
309
218
  const len0 = WASM_VECTOR_LEN;
@@ -311,631 +220,580 @@ class RRegex {
311
220
  return ret !== 0;
312
221
  }
313
222
  /**
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
- */
339
- find(text) {
223
+ * Replaces all non-overlapping matches in `text` with the replacement
224
+ * provided. This is the same as calling `replacen` with `limit` set to
225
+ * `0`.
226
+ *
227
+ * See the documentation for `replace` for details on how to access
228
+ * capturing group matches in the replacement string.
229
+ *
230
+ * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
231
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
232
+ * @param {string} text - The string against which to match the regular expression
233
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
234
+ * @returns {string}
235
+ */
236
+ replaceAll(text, rep) {
237
+ let deferred3_0;
238
+ let deferred3_1;
340
239
  try {
341
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
342
240
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
343
241
  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);
242
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
243
+ const len1 = WASM_VECTOR_LEN;
244
+ const ret = wasm.rregex_replaceAll(this.__wbg_ptr, ptr0, len0, ptr1, len1);
245
+ deferred3_0 = ret[0];
246
+ deferred3_1 = ret[1];
247
+ return getStringFromWasm0(ret[0], ret[1]);
352
248
  } finally {
353
- wasm.__wbindgen_add_to_stack_pointer(16);
249
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
354
250
  }
355
251
  }
356
252
  /**
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
- */
369
- 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);
253
+ * Returns a list with all the non-overlapping capture groups matched
254
+ * in `text`. This is operationally the same as `findAll`, except it
255
+ * returns information about capturing group matches.
256
+ *
257
+ * # Example
258
+ *
259
+ * We can use this to find all movie titles and their release years in
260
+ * some text, where the movie is formatted like "'Title' (xxxx)":
261
+ *
262
+ * ```typescript
263
+ * import { RRegex } from "rregex"
264
+ *
265
+ * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
266
+ * const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
267
+ * for caps of re.captures_iter(text) {
268
+ * console.log(
269
+ * "Movie:", caps.name["title"].value, ","
270
+ * "Released:", caps.name["year"].value
271
+ * );
272
+ * }
273
+ * // Output:
274
+ * // Movie: Citizen Kane, Released: 1941
275
+ * // Movie: The Wizard of Oz, Released: 1939
276
+ * // Movie: M, Released: 1931
277
+ * ```
278
+ *
279
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
280
+ * @param {string} text - The string against which to match the regular expression
281
+ * @returns {Captures[]}
282
+ */
283
+ capturesAll(text) {
284
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
285
+ const len0 = WASM_VECTOR_LEN;
286
+ const ret = wasm.rregex_capturesAll(this.__wbg_ptr, ptr0, len0);
287
+ if (ret[2]) {
288
+ throw takeFromExternrefTable0(ret[1]);
384
289
  }
290
+ return takeFromExternrefTable0(ret[0]);
385
291
  }
386
292
  /**
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
- */
406
- 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);
421
- }
293
+ * Returns the number of captures.
294
+ *
295
+ * This includes all named and unnamed groups, including the implicit
296
+ * unnamed group that is always present and corresponds to the entire match.
297
+ *
298
+ * Since the implicit unnamed group is always included in this length, the
299
+ * length returned is guaranteed to be greater than zero.
300
+ *
301
+ * ## Example
302
+ *
303
+ * ```typescript
304
+ * import { RRegex } from "rregex"
305
+ *
306
+ * const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
307
+ * expect(re1.capturesLength()).toEqual(4)
308
+ *
309
+ * const re2 = new RRegex("foo")
310
+ * expect(re2.capturesLength()).toEqual(1)
311
+ *
312
+ * const re3 = new RRegex("(foo)")
313
+ * expect(re3.capturesLength()).toEqual(2)
314
+ *
315
+ * const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
316
+ * expect(re4.capturesLength()).toEqual(5)
317
+ *
318
+ * const re5 = new RRegex("[a&&b]")
319
+ * expect(re5.capturesLength()).toEqual(1)
320
+ * ```
321
+ *
322
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
323
+ * @returns {number}
324
+ */
325
+ capturesLength() {
326
+ const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
327
+ return ret >>> 0;
422
328
  }
423
329
  /**
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
- */
330
+ * Returns a list of the capture names in this regex.
331
+ *
332
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
333
+ */
428
334
  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
- }
335
+ const ret = wasm.rregex_captureNames(this.__wbg_ptr);
336
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
337
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
338
+ return v1;
440
339
  }
441
340
  /**
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
- */
488
- 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);
341
+ * Returns the end location of a match in the text given.
342
+ *
343
+ * This method may have the same performance characteristics as
344
+ * `isMatch`, except it provides an end location for a match. In
345
+ * particular, the location returned *may be shorter* than the proper end
346
+ * of the leftmost-first match that you would find via `Regex.find`.
347
+ *
348
+ * Note that it is not guaranteed that this routine finds the shortest or
349
+ * "earliest" possible match. Instead, the main idea of this API is that
350
+ * it returns the offset at the point at which the internal regex engine
351
+ * has determined that a match has occurred. This may vary depending on
352
+ * which internal regex engine is used, and thus, the offset itself may
353
+ * change.
354
+ *
355
+ * # Example
356
+ *
357
+ * Typically, `a+` would match the entire first sequence of `a` in some
358
+ * text, but `shortest_match` can give up as soon as it sees the first
359
+ * `a`.
360
+ *
361
+ * ```typescript
362
+ * import { RRegex } from "rregex"
363
+ *
364
+ * const text = "aaaaa"
365
+ * const = new RRegex("a+").shortest_match(text)
366
+ * expect(pos).toBe(1)
367
+ * ```
368
+ *
369
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
370
+ * @param {string} text - The string against which to match the regular expression
371
+ * @returns {number|undefined}
372
+ */
373
+ shortestMatch(text) {
374
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
375
+ const len0 = WASM_VECTOR_LEN;
376
+ const ret = wasm.rregex_shortestMatch(this.__wbg_ptr, ptr0, len0);
377
+ return ret === 0x100000001 ? undefined : ret;
378
+ }
379
+ /**
380
+ * Returns the same as `shortest_match`, but starts the search at the
381
+ * given offset.
382
+ *
383
+ * The significance of the starting point is that it takes the surrounding
384
+ * context into consideration. For example, the `\A` anchor can only match
385
+ * when `start == 0`.
386
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
387
+ * @param {string} text - The string against which to match the regular expression
388
+ * @param {number} start - Zero-based index at which to start matching
389
+ * @returns {number|undefined}
390
+ */
391
+ shortestMatchAt(text, start) {
392
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
393
+ const len0 = WASM_VECTOR_LEN;
394
+ const ret = wasm.rregex_shortestMatchAt(this.__wbg_ptr, ptr0, len0, start);
395
+ return ret === 0x100000001 ? undefined : ret;
396
+ }
397
+ /**
398
+ * Compiles a regular expression. Once compiled, it can be used repeatedly
399
+ * to search, split or replace text in a string.
400
+ *
401
+ * If an invalid expression is given, then an error is returned.
402
+ * @param {string} re
403
+ */
404
+ constructor(re) {
405
+ const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
406
+ const len0 = WASM_VECTOR_LEN;
407
+ const ret = wasm.rregex_new(ptr0, len0);
408
+ if (ret[2]) {
409
+ throw takeFromExternrefTable0(ret[1]);
503
410
  }
411
+ this.__wbg_ptr = ret[0] >>> 0;
412
+ RRegexFinalization.register(this, this.__wbg_ptr, this);
413
+ return this;
504
414
  }
505
415
  /**
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
- */
536
- 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);
416
+ * Returns the start and end byte range of the leftmost-first match in
417
+ * `text`. If no match exists, then `undefined` is returned.
418
+ *
419
+ * Note that this should only be used if you want to discover the position
420
+ * of the match. Testing the existence of a match is faster if you use
421
+ * `isMatch`.
422
+ *
423
+ * # Example
424
+ *
425
+ * Find the start and end location of the first word with exactly 13
426
+ * Unicode word characters:
427
+ *
428
+ * ```typescript
429
+ * import { RRegex } from "rregex"
430
+ *
431
+ * const text = "I categorically deny having triskaidekaphobia."
432
+ * const m = new RRegex("\\b\\w{13}\\b").find(text)
433
+ * expect(m.start).toBe(2)
434
+ * expect(m.end).toBe(15)
435
+ * ```
436
+ *
437
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find
438
+ * @param {string} text - The string against which to match the regular expression
439
+ * @return {Match}
440
+ */
441
+ find(text) {
442
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
443
+ const len0 = WASM_VECTOR_LEN;
444
+ const ret = wasm.rregex_find(this.__wbg_ptr, ptr0, len0);
445
+ if (ret[2]) {
446
+ throw takeFromExternrefTable0(ret[1]);
551
447
  }
448
+ return takeFromExternrefTable0(ret[0]);
552
449
  }
553
450
  /**
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
- */
586
- capturesLength() {
587
- const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
588
- return ret >>> 0;
451
+ * Returns an iterator of substrings of `text` delimited by a match of the
452
+ * regular expression. Namely, each element of the iterator corresponds to
453
+ * text that *isn't* matched by the regular expression.
454
+ *
455
+ * This method will *not* copy the text given.
456
+ *
457
+ * # Example
458
+ *
459
+ * To split a string delimited by arbitrary amounts of spaces or tabs:
460
+ *
461
+ * ```typescript
462
+ * import { RRegex } from "rregex"
463
+ *
464
+ * const re = new RRegex(r"[ \\t]+")
465
+ * const fields = re.split("a b \t c\td e")
466
+ * expect(fields).toEqual(["a", "b", "c", "d", "e"])
467
+ * ```
468
+ *
469
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
470
+ * @param {string} text - The string against which to match the regular expression
471
+ * @returns {string[]}
472
+ */
473
+ split(text) {
474
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
475
+ const len0 = WASM_VECTOR_LEN;
476
+ const ret = wasm.rregex_split(this.__wbg_ptr, ptr0, len0);
477
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
478
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
479
+ return v2;
589
480
  }
590
481
  /**
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
- */
665
- replace(text, rep) {
666
- let deferred3_0;
667
- let deferred3_1;
668
- try {
669
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
670
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
671
- const len0 = WASM_VECTOR_LEN;
672
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
673
- 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);
680
- } finally {
681
- wasm.__wbindgen_add_to_stack_pointer(16);
682
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
482
+ * Returns an iterator of at most `limit` substrings of `text` delimited
483
+ * by a match of the regular expression. (A `limit` of `0` will return no
484
+ * substrings.) Namely, each element of the iterator corresponds to text
485
+ * that *isn't* matched by the regular expression. The remainder of the
486
+ * string that is not split will be the last element in the iterator.
487
+ *
488
+ * This method will *not* copy the text given.
489
+ *
490
+ * # Example
491
+ *
492
+ * Get the first two words in some text:
493
+ *
494
+ * ```typescript
495
+ * import { RRegex } from "rregex"
496
+ *
497
+ * const re = new RRegex(r"\\W+")
498
+ * const fields = re.splitn("Hey! How are you?", 3)
499
+ * expect(fields).toEqual(["Hey", "How", "are you?"])
500
+ * ```
501
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
502
+ * @param {string} text - The string against which to match the regular expression
503
+ * @param {number} limit - Max number result elements
504
+ * @returns {string[]}
505
+ */
506
+ splitn(text, limit) {
507
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
508
+ const len0 = WASM_VECTOR_LEN;
509
+ const ret = wasm.rregex_splitn(this.__wbg_ptr, ptr0, len0, limit);
510
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
511
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
512
+ return v2;
513
+ }
514
+ /**
515
+ * Returns the regular expression into a high level intermediate
516
+ * representation.
517
+ * @returns {any}
518
+ */
519
+ syntax() {
520
+ const ret = wasm.rregex_syntax(this.__wbg_ptr);
521
+ if (ret[2]) {
522
+ throw takeFromExternrefTable0(ret[1]);
683
523
  }
524
+ return takeFromExternrefTable0(ret[0]);
684
525
  }
685
526
  /**
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
- */
699
- replacen(text, limit, rep) {
700
- let deferred3_0;
701
- let deferred3_1;
702
- try {
703
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
704
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
705
- const len0 = WASM_VECTOR_LEN;
706
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
707
- 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);
714
- } finally {
715
- wasm.__wbindgen_add_to_stack_pointer(16);
716
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
527
+ * Returns the same as find, but starts the search at the given
528
+ * offset.
529
+ *
530
+ * The significance of the starting point is that it takes the surrounding
531
+ * context into consideration. For example, the `\A` anchor can only
532
+ * match when `start == 0`.
533
+ *
534
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
535
+ * @param {string} text - The string against which to match the regular expression
536
+ * @param {number} start - Zero-based index at which to start matching
537
+ * @returns {Match}
538
+ */
539
+ findAt(text, start) {
540
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
541
+ const len0 = WASM_VECTOR_LEN;
542
+ const ret = wasm.rregex_findAt(this.__wbg_ptr, ptr0, len0, start);
543
+ if (ret[2]) {
544
+ throw takeFromExternrefTable0(ret[1]);
717
545
  }
546
+ return takeFromExternrefTable0(ret[0]);
718
547
  }
719
548
  /**
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
- */
733
- replaceAll(text, rep) {
549
+ * Replaces the leftmost-first match with the replacement provided.
550
+ * The replacement can be a regular string (where `$N` and `$name` are
551
+ * expanded to match capture groups) or a function that takes the matches'
552
+ * `Captures` and returns the replaced string.
553
+ *
554
+ * If no match is found, then a copy of the string is returned unchanged.
555
+ *
556
+ * # Replacement string syntax
557
+ *
558
+ * All instances of `$name` in the replacement text is replaced with the
559
+ * corresponding capture group `name`.
560
+ *
561
+ * `name` may be an integer corresponding to the index of the
562
+ * capture group (counted by order of opening parenthesis where `0` is the
563
+ * entire match) or it can be a name (consisting of letters, digits or
564
+ * underscores) corresponding to a named capture group.
565
+ *
566
+ * If `name` isn't a valid capture group (whether the name doesn't exist
567
+ * or isn't a valid index), then it is replaced with the empty string.
568
+ *
569
+ * The longest possible name is used. e.g., `$1a` looks up the capture
570
+ * group named `1a` and not the capture group at index `1`. To exert more
571
+ * precise control over the name, use braces, e.g., `${1}a`.
572
+ *
573
+ * To write a literal `$` use `$$`.
574
+ *
575
+ * # Examples
576
+ *
577
+ * Note that this function is polymorphic with respect to the replacement.
578
+ * In typical usage, this can just be a normal string:
579
+ *
580
+ * ```typescript
581
+ * import { RRegex } from "rregex"
582
+ *
583
+ * const re = new RRegex("[^01]+")
584
+ * expect(re.replace("1078910", "").toBe("1010")
585
+ * ```
586
+ *
587
+ * Here's the example using this expansion technique with named capture
588
+ * groups:
589
+ *
590
+ * ```typescript
591
+ * import { RRegex } from "rregex"
592
+ *
593
+ * const re = new RRegex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")
594
+ * const result = re.replace("Springsteen, Bruce", "$first $last")
595
+ * expect(result).toBe("Bruce Springsteen")
596
+ * ```
597
+ *
598
+ * Note that using `$2` instead of `$first` or `$1` instead of `$last`
599
+ * would produce the same result. To write a literal `$` use `$$`.
600
+ *
601
+ * Sometimes the replacement string requires use of curly braces to
602
+ * delineate a capture group replacement and surrounding literal text.
603
+ * For example, if we wanted to join two words together with an
604
+ * underscore:
605
+ *
606
+ * ```typescript
607
+ * import { RRegex } from "rregex"
608
+ *
609
+ * const re = new RRegex("(?P<first>\\w+)\\s+(?P<second>\\w+)")
610
+ * const result = re.replace("deep fried", "${first}_$second")
611
+ * expect(result).toBe("deep_fried")
612
+ * ```
613
+ *
614
+ * Without the curly braces, the capture group name `first_` would be
615
+ * used, and since it doesn't exist, it would be replaced with the empty
616
+ * string.
617
+ *
618
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace
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
+ */
623
+ replace(text, rep) {
734
624
  let deferred3_0;
735
625
  let deferred3_1;
736
626
  try {
737
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
738
627
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
739
628
  const len0 = WASM_VECTOR_LEN;
740
629
  const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
741
630
  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);
631
+ const ret = wasm.rregex_replace(this.__wbg_ptr, ptr0, len0, ptr1, len1);
632
+ deferred3_0 = ret[0];
633
+ deferred3_1 = ret[1];
634
+ return getStringFromWasm0(ret[0], ret[1]);
748
635
  } finally {
749
- wasm.__wbindgen_add_to_stack_pointer(16);
750
636
  wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
751
637
  }
752
638
  }
753
639
  /**
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
- */
776
- 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);
640
+ * Returns the capture groups corresponding to the leftmost-first
641
+ * match in `text`. Capture group `0` always corresponds to the entire
642
+ * match. If no match is found, then `undefined` is returned.
643
+ *
644
+ * You should only use `captures` if you need access to the location of
645
+ * capturing group matches. Otherwise, `find` is faster for discovering
646
+ * the location of the overall match.
647
+ *
648
+ * # Examples
649
+ *
650
+ * Say you have some text with movie names and their release years,
651
+ * like "'Citizen Kane' (1941)". It'd be nice if we could search for text
652
+ * looking like that, while also extracting the movie name and its release
653
+ * year separately.
654
+ *
655
+ * ```typescript
656
+ * import { RRegex } from "rregex"
657
+ *
658
+ * const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
659
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
660
+ * const caps = re.captures(text)
661
+ * expect(caps.get[1].value).toBe("Citizen Kane")
662
+ * expect(caps.get[2].value).toBe("1941")
663
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
664
+ * ```
665
+ *
666
+ * Note that the full match is at capture group `0`. Each subsequent
667
+ * capture group is indexed by the order of its opening `(`.
668
+ *
669
+ * We can make this example a bit clearer by using *named* capture groups:
670
+ *
671
+ * ```typescript
672
+ * import { RRegex } from "rregex"
673
+ *
674
+ * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
675
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
676
+ * const caps = re.captures(text)
677
+ * expect(caps.name["title"].value).toBe("Citizen Kane")
678
+ * expect(caps.name["year"].value).toBe("1941")
679
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
680
+ * ```
681
+ *
682
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
683
+ * @param {string} text - The string against which to match the regular expression
684
+ * @returns {Captures|undefined}
685
+ */
686
+ captures(text) {
687
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
688
+ const len0 = WASM_VECTOR_LEN;
689
+ const ret = wasm.rregex_captures(this.__wbg_ptr, ptr0, len0);
690
+ if (ret[2]) {
691
+ throw takeFromExternrefTable0(ret[1]);
789
692
  }
693
+ return takeFromExternrefTable0(ret[0]);
790
694
  }
791
695
  /**
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
- */
816
- 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);
696
+ * Returns an array for each successive non-overlapping match in `text``,
697
+ * returning the start and end byte indices with respect to `text`.
698
+ *
699
+ * # Example
700
+ *
701
+ * Find the start and end location of every word with exactly 13 Unicode
702
+ * word characters:
703
+ *
704
+ * ```typescript
705
+ * import { RRegex } from "rregex"
706
+ *
707
+ * const text = "Retroactively relinquishing remunerations is reprehensible."
708
+ * const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
709
+ * ```
710
+ *
711
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
712
+ * @param {string} text - The string against which to match the regular expression
713
+ * @returns {Match}
714
+ */
715
+ findAll(text) {
716
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
717
+ const len0 = WASM_VECTOR_LEN;
718
+ const ret = wasm.rregex_findAll(this.__wbg_ptr, ptr0, len0);
719
+ if (ret[2]) {
720
+ throw takeFromExternrefTable0(ret[1]);
829
721
  }
722
+ return takeFromExternrefTable0(ret[0]);
830
723
  }
831
724
  /**
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
- */
864
- 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
- }
725
+ * Returns true if and only if there is a match for the regex in the
726
+ * string given.
727
+ *
728
+ * It is recommended to use this method if all you need to do is test
729
+ * a match, since the underlying matching engine may be able to do less
730
+ * work.
731
+ *
732
+ * # Example
733
+ *
734
+ * Test if some text contains at least one word with exactly 13
735
+ * Unicode word characters:
736
+ *
737
+ * ```typescript
738
+ * import { RRegex } from "rregex"
739
+ *
740
+ * const text = "I categorically deny having triskaidekaphobia."
741
+ * expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
742
+ * ```
743
+ *
744
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
745
+ * @param {string} text - The string against which to match the regular expression
746
+ * @return {boolean}
747
+ */
748
+ isMatch(text) {
749
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
750
+ const len0 = WASM_VECTOR_LEN;
751
+ const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
752
+ return ret !== 0;
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
- */
889
- shortestMatchAt(text, start) {
755
+ * Replaces at most `limit` non-overlapping matches in `text` with the
756
+ * replacement provided. If `limit` is 0, then all non-overlapping matches
757
+ * are replaced.
758
+ *
759
+ * See the documentation for `replace` for details on how to access
760
+ * capturing group matches in the replacement string.
761
+ *
762
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
763
+ * @param {string} text - The string against which to match the regular expression
764
+ * @param {number} limit - Max number of replacement
765
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
766
+ * @returns {string}
767
+ */
768
+ replacen(text, limit, rep) {
769
+ let deferred3_0;
770
+ let deferred3_1;
890
771
  try {
891
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
892
772
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
893
773
  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
- }
901
- }
902
- /**
903
- * Returns the regular expression into a high level intermediate
904
- * representation.
905
- * @returns {any}
906
- */
907
- 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);
774
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
775
+ const len1 = WASM_VECTOR_LEN;
776
+ const ret = wasm.rregex_replacen(this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
777
+ deferred3_0 = ret[0];
778
+ deferred3_1 = ret[1];
779
+ return getStringFromWasm0(ret[0], ret[1]);
918
780
  } finally {
919
- wasm.__wbindgen_add_to_stack_pointer(16);
781
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
920
782
  }
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,246 +826,233 @@ 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 the set of regular expressions that match in the given text.
860
+ *
861
+ * The set returned contains the index of each regular expression that
862
+ * matches in the given text. The index is in correspondence with the
863
+ * order of regular expressions given to `RegexSet`'s constructor.
864
+ *
865
+ * The set can also be used to iterate over the matched indices.
866
+ *
867
+ * Note that as with searches using `Regex`, the expression is unanchored
868
+ * by default. That is, if the regex does not start with `^` or `\A`, or
869
+ * end with `$` or `\z`, then it is permitted to match anywhere in the
870
+ * text.
871
+ *
872
+ * # Example
873
+ *
874
+ * Tests which regular expressions match the given text:
875
+ *
876
+ * ```typescript
877
+ * import { RegexSet } from "rregex"
878
+ *
879
+ * const set = new RegexSet([
880
+ * "\\w+",
881
+ * "\\d+",
882
+ * "\\pL+",
883
+ * "foo",
884
+ * "bar",
885
+ * "barfoo",
886
+ * "foobar",
887
+ * ])
888
+ * const matches = set.matches("foobar")
889
+ * expect(matches).toBe([0, 2, 3, 4, 6])
890
+ * ```
891
+ *
892
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.matches
893
+ * @param {string} text - The string against which to match the regular expression
894
+ * @return {number[]}
895
+ */
896
+ matches(text) {
897
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
898
+ const len0 = WASM_VECTOR_LEN;
899
+ const ret = wasm.rregexset_matches(this.__wbg_ptr, ptr0, len0);
900
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
901
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
902
+ return v2;
903
+ }
904
+ /**
905
+ * Returns true if and only if one of the regexes in this set matches
906
+ * the text given.
907
+ *
908
+ * This method should be preferred if you only need to test whether any
909
+ * of the regexes in the set should match, but don't care about *which*
910
+ * regexes matched. This is because the underlying matching engine will
911
+ * quit immediately after seeing the first match instead of continuing to
912
+ * find all matches.
913
+ *
914
+ * Note that as with searches using `Regex`, the expression is unanchored
915
+ * by default. That is, if the regex does not start with `^` or `\A`, or
916
+ * end with `$` or `\z`, then it is permitted to match anywhere in the
917
+ * text.
918
+ *
919
+ * # Example
920
+ *
921
+ * Tests whether a set matches some text:
922
+ *
923
+ * ```typescript
924
+ * import { RegexSet } from "rregex"
925
+ *
926
+ * const set = new RegexSet(["\\w+", "\\d+"])
927
+ * expect(set.is_match("foo")).toBe(true)
928
+ * expect(!set.is_match("☃")).toBe(false)
929
+ * ```
930
+ *
931
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
932
+ * @param {string} text - The string against which to match the regular expression
933
+ * @return {boolean}
934
+ */
1039
935
  isMatch(text) {
1040
936
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1041
937
  const len0 = WASM_VECTOR_LEN;
1042
938
  const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
1043
939
  return ret !== 0;
1044
940
  }
1045
- /**
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
- */
1083
- 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
- }
1097
- }
1098
941
  }
1099
942
  module.exports.RRegexSet = RRegexSet;
1100
943
 
1101
- module.exports.__wbindgen_number_new = function(arg0) {
1102
- const ret = arg0;
1103
- return addHeapObject(ret);
944
+ module.exports.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
945
+ const ret = arg0.buffer;
946
+ return ret;
1104
947
  };
1105
948
 
1106
- module.exports.__wbindgen_object_drop_ref = function(arg0) {
1107
- takeObject(arg0);
1108
- };
949
+ module.exports.__wbg_fromCodePoint_f37c25c172f2e8b5 = function() { return handleError(function (arg0) {
950
+ const ret = String.fromCodePoint(arg0 >>> 0);
951
+ return ret;
952
+ }, arguments) };
1109
953
 
1110
- module.exports.__wbindgen_string_new = function(arg0, arg1) {
1111
- const ret = getStringFromWasm0(arg0, arg1);
1112
- return addHeapObject(ret);
954
+ module.exports.__wbg_from_2a5d3e218e67aa85 = 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_b9b93047fe3cf45b = 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_e2d2a49132c1b256 = 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_405e22f390576ce2 = function() {
970
+ const ret = new Object();
971
+ return ret;
1132
972
  };
1133
973
 
1134
- module.exports.__wbg_set_f975102236d3c502 = function(arg0, arg1, arg2) {
1135
- getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
974
+ module.exports.__wbg_new_78feb108b6472713 = function() {
975
+ const ret = new Array();
976
+ return ret;
1136
977
  };
1137
978
 
1138
- module.exports.__wbindgen_object_clone_ref = function(arg0) {
1139
- const ret = getObject(arg0);
1140
- return addHeapObject(ret);
979
+ module.exports.__wbg_new_a12002a7f91c75be = function(arg0) {
980
+ const ret = new Uint8Array(arg0);
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_d97e637ebe145a9a = 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_737cfc8c1432c2c6 = 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_37837023f3d740e8 = 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_bb8cecf6a62b9f46 = 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
+