rregex 1.10.11 → 1.10.13

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