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