rregex 1.11.0 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/commonjs.cjs CHANGED
@@ -203,69 +203,214 @@ class RRegex {
203
203
  wasm.__wbg_rregex_free(ptr, 0);
204
204
  }
205
205
  /**
206
- * Compiles a regular expression. Once compiled, it can be used repeatedly
207
- * to search, split or replace text in a string.
206
+ * Returns the same as is_match, but starts the search at the given offset.
207
+ * The significance of the starting point is that it takes the surrounding
208
+ * context into consideration. For example, the `\A` anchor can only match
209
+ * when `start == 0`.
208
210
  *
209
- * If an invalid expression is given, then an error is returned.
210
- * @param {string} re
211
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
212
+ * @param {string} text - The string against which to match the regular expression
213
+ * @param {number} start - Zero-based index at which to start matching
214
+ * @return {boolean}
211
215
  */
212
- constructor(re) {
213
- const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
216
+ isMatchAt(text, start) {
217
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
214
218
  const len0 = WASM_VECTOR_LEN;
215
- const ret = wasm.rregex_new(ptr0, len0);
219
+ const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
220
+ return ret !== 0;
221
+ }
222
+ /**
223
+ * Replaces all non-overlapping matches in `text` with the replacement
224
+ * provided. This is the same as calling `replacen` with `limit` set to
225
+ * `0`.
226
+ *
227
+ * See the documentation for `replace` for details on how to access
228
+ * capturing group matches in the replacement string.
229
+ *
230
+ * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
231
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
232
+ * @param {string} text - The string against which to match the regular expression
233
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
234
+ * @returns {string}
235
+ */
236
+ replaceAll(text, rep) {
237
+ let deferred3_0;
238
+ let deferred3_1;
239
+ try {
240
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
241
+ const len0 = WASM_VECTOR_LEN;
242
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
243
+ const len1 = WASM_VECTOR_LEN;
244
+ const ret = wasm.rregex_replaceAll(this.__wbg_ptr, ptr0, len0, ptr1, len1);
245
+ deferred3_0 = ret[0];
246
+ deferred3_1 = ret[1];
247
+ return getStringFromWasm0(ret[0], ret[1]);
248
+ } finally {
249
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
250
+ }
251
+ }
252
+ /**
253
+ * Returns a list with all the non-overlapping capture groups matched
254
+ * in `text`. This is operationally the same as `findAll`, except it
255
+ * returns information about capturing group matches.
256
+ *
257
+ * # Example
258
+ *
259
+ * We can use this to find all movie titles and their release years in
260
+ * some text, where the movie is formatted like "'Title' (xxxx)":
261
+ *
262
+ * ```typescript
263
+ * import { RRegex } from "rregex"
264
+ *
265
+ * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
266
+ * const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
267
+ * for caps of re.captures_iter(text) {
268
+ * console.log(
269
+ * "Movie:", caps.name["title"].value, ","
270
+ * "Released:", caps.name["year"].value
271
+ * );
272
+ * }
273
+ * // Output:
274
+ * // Movie: Citizen Kane, Released: 1941
275
+ * // Movie: The Wizard of Oz, Released: 1939
276
+ * // Movie: M, Released: 1931
277
+ * ```
278
+ *
279
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
280
+ * @param {string} text - The string against which to match the regular expression
281
+ * @returns {Captures[]}
282
+ */
283
+ capturesAll(text) {
284
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
285
+ const len0 = WASM_VECTOR_LEN;
286
+ const ret = wasm.rregex_capturesAll(this.__wbg_ptr, ptr0, len0);
216
287
  if (ret[2]) {
217
288
  throw takeFromExternrefTable0(ret[1]);
218
289
  }
219
- this.__wbg_ptr = ret[0] >>> 0;
220
- RRegexFinalization.register(this, this.__wbg_ptr, this);
221
- return this;
290
+ return takeFromExternrefTable0(ret[0]);
222
291
  }
223
292
  /**
224
- * Returns true if and only if there is a match for the regex in the
225
- * string given.
293
+ * Returns the number of captures.
226
294
  *
227
- * It is recommended to use this method if all you need to do is test
228
- * a match, since the underlying matching engine may be able to do less
229
- * work.
295
+ * This includes all named and unnamed groups, including the implicit
296
+ * unnamed group that is always present and corresponds to the entire match.
297
+ *
298
+ * Since the implicit unnamed group is always included in this length, the
299
+ * length returned is guaranteed to be greater than zero.
300
+ *
301
+ * ## Example
302
+ *
303
+ * ```typescript
304
+ * import { RRegex } from "rregex"
305
+ *
306
+ * const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
307
+ * expect(re1.capturesLength()).toEqual(4)
308
+ *
309
+ * const re2 = new RRegex("foo")
310
+ * expect(re2.capturesLength()).toEqual(1)
311
+ *
312
+ * const re3 = new RRegex("(foo)")
313
+ * expect(re3.capturesLength()).toEqual(2)
314
+ *
315
+ * const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
316
+ * expect(re4.capturesLength()).toEqual(5)
317
+ *
318
+ * const re5 = new RRegex("[a&&b]")
319
+ * expect(re5.capturesLength()).toEqual(1)
320
+ * ```
321
+ *
322
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
323
+ * @returns {number}
324
+ */
325
+ capturesLength() {
326
+ const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
327
+ return ret >>> 0;
328
+ }
329
+ /**
330
+ * Returns a list of the capture names in this regex.
331
+ *
332
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
333
+ */
334
+ captureNames() {
335
+ const ret = wasm.rregex_captureNames(this.__wbg_ptr);
336
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
337
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
338
+ return v1;
339
+ }
340
+ /**
341
+ * Returns the end location of a match in the text given.
342
+ *
343
+ * This method may have the same performance characteristics as
344
+ * `isMatch`, except it provides an end location for a match. In
345
+ * particular, the location returned *may be shorter* than the proper end
346
+ * of the leftmost-first match that you would find via `Regex.find`.
347
+ *
348
+ * Note that it is not guaranteed that this routine finds the shortest or
349
+ * "earliest" possible match. Instead, the main idea of this API is that
350
+ * it returns the offset at the point at which the internal regex engine
351
+ * has determined that a match has occurred. This may vary depending on
352
+ * which internal regex engine is used, and thus, the offset itself may
353
+ * change.
230
354
  *
231
355
  * # Example
232
356
  *
233
- * Test if some text contains at least one word with exactly 13
234
- * Unicode word characters:
357
+ * Typically, `a+` would match the entire first sequence of `a` in some
358
+ * text, but `shortest_match` can give up as soon as it sees the first
359
+ * `a`.
235
360
  *
236
361
  * ```typescript
237
362
  * import { RRegex } from "rregex"
238
363
  *
239
- * const text = "I categorically deny having triskaidekaphobia."
240
- * expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
364
+ * const text = "aaaaa"
365
+ * const = new RRegex("a+").shortest_match(text)
366
+ * expect(pos).toBe(1)
241
367
  * ```
242
368
  *
243
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
369
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
244
370
  * @param {string} text - The string against which to match the regular expression
245
- * @return {boolean}
371
+ * @returns {number|undefined}
246
372
  */
247
- isMatch(text) {
373
+ shortestMatch(text) {
248
374
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
249
375
  const len0 = WASM_VECTOR_LEN;
250
- const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
251
- return ret !== 0;
376
+ const ret = wasm.rregex_shortestMatch(this.__wbg_ptr, ptr0, len0);
377
+ return ret === 0x100000001 ? undefined : ret;
252
378
  }
253
379
  /**
254
- * Returns the same as is_match, but starts the search at the given offset.
380
+ * Returns the same as `shortest_match`, but starts the search at the
381
+ * given offset.
382
+ *
255
383
  * The significance of the starting point is that it takes the surrounding
256
384
  * context into consideration. For example, the `\A` anchor can only match
257
385
  * when `start == 0`.
258
- *
259
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match_at
386
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
260
387
  * @param {string} text - The string against which to match the regular expression
261
388
  * @param {number} start - Zero-based index at which to start matching
262
- * @return {boolean}
389
+ * @returns {number|undefined}
263
390
  */
264
- isMatchAt(text, start) {
391
+ shortestMatchAt(text, start) {
265
392
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
266
393
  const len0 = WASM_VECTOR_LEN;
267
- const ret = wasm.rregex_isMatchAt(this.__wbg_ptr, ptr0, len0, start);
268
- return ret !== 0;
394
+ const ret = wasm.rregex_shortestMatchAt(this.__wbg_ptr, ptr0, len0, start);
395
+ return ret === 0x100000001 ? undefined : ret;
396
+ }
397
+ /**
398
+ * Compiles a regular expression. Once compiled, it can be used repeatedly
399
+ * to search, split or replace text in a string.
400
+ *
401
+ * If an invalid expression is given, then an error is returned.
402
+ * @param {string} re
403
+ */
404
+ constructor(re) {
405
+ const ptr0 = passStringToWasm0(re, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
406
+ const len0 = WASM_VECTOR_LEN;
407
+ const ret = wasm.rregex_new(ptr0, len0);
408
+ if (ret[2]) {
409
+ throw takeFromExternrefTable0(ret[1]);
410
+ }
411
+ this.__wbg_ptr = ret[0] >>> 0;
412
+ RRegexFinalization.register(this, this.__wbg_ptr, this);
413
+ return this;
269
414
  }
270
415
  /**
271
416
  * Returns the start and end byte range of the leftmost-first match in
@@ -303,200 +448,103 @@ class RRegex {
303
448
  return takeFromExternrefTable0(ret[0]);
304
449
  }
305
450
  /**
306
- * Returns the same as find, but starts the search at the given
307
- * offset.
308
- *
309
- * The significance of the starting point is that it takes the surrounding
310
- * context into consideration. For example, the `\A` anchor can only
311
- * match when `start == 0`.
451
+ * Returns an iterator of substrings of `text` delimited by a match of the
452
+ * regular expression. Namely, each element of the iterator corresponds to
453
+ * text that *isn't* matched by the regular expression.
312
454
  *
313
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
314
- * @param {string} text - The string against which to match the regular expression
315
- * @param {number} start - Zero-based index at which to start matching
316
- * @returns {Match}
317
- */
318
- findAt(text, start) {
319
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
320
- const len0 = WASM_VECTOR_LEN;
321
- const ret = wasm.rregex_findAt(this.__wbg_ptr, ptr0, len0, start);
322
- if (ret[2]) {
323
- throw takeFromExternrefTable0(ret[1]);
324
- }
325
- return takeFromExternrefTable0(ret[0]);
326
- }
327
- /**
328
- * Returns an array for each successive non-overlapping match in `text``,
329
- * returning the start and end byte indices with respect to `text`.
455
+ * This method will *not* copy the text given.
330
456
  *
331
457
  * # Example
332
458
  *
333
- * Find the start and end location of every word with exactly 13 Unicode
334
- * word characters:
459
+ * To split a string delimited by arbitrary amounts of spaces or tabs:
335
460
  *
336
461
  * ```typescript
337
462
  * import { RRegex } from "rregex"
338
463
  *
339
- * const text = "Retroactively relinquishing remunerations is reprehensible."
340
- * const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
464
+ * const re = new RRegex(r"[ \\t]+")
465
+ * const fields = re.split("a b \t c\td e")
466
+ * expect(fields).toEqual(["a", "b", "c", "d", "e"])
341
467
  * ```
342
468
  *
343
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
469
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
344
470
  * @param {string} text - The string against which to match the regular expression
345
- * @returns {Match}
471
+ * @returns {string[]}
346
472
  */
347
- findAll(text) {
473
+ split(text) {
348
474
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
349
475
  const len0 = WASM_VECTOR_LEN;
350
- const ret = wasm.rregex_findAll(this.__wbg_ptr, ptr0, len0);
351
- if (ret[2]) {
352
- throw takeFromExternrefTable0(ret[1]);
353
- }
354
- return takeFromExternrefTable0(ret[0]);
355
- }
356
- /**
357
- * Returns a list of the capture names in this regex.
358
- *
359
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.capture_names
360
- */
361
- captureNames() {
362
- const ret = wasm.rregex_captureNames(this.__wbg_ptr);
363
- var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
476
+ const ret = wasm.rregex_split(this.__wbg_ptr, ptr0, len0);
477
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
364
478
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
365
- return v1;
479
+ return v2;
366
480
  }
367
481
  /**
368
- * Returns the capture groups corresponding to the leftmost-first
369
- * match in `text`. Capture group `0` always corresponds to the entire
370
- * match. If no match is found, then `undefined` is returned.
371
- *
372
- * You should only use `captures` if you need access to the location of
373
- * capturing group matches. Otherwise, `find` is faster for discovering
374
- * the location of the overall match.
375
- *
376
- * # Examples
377
- *
378
- * Say you have some text with movie names and their release years,
379
- * like "'Citizen Kane' (1941)". It'd be nice if we could search for text
380
- * looking like that, while also extracting the movie name and its release
381
- * year separately.
382
- *
383
- * ```typescript
384
- * import { RRegex } from "rregex"
482
+ * Returns an iterator of at most `limit` substrings of `text` delimited
483
+ * by a match of the regular expression. (A `limit` of `0` will return no
484
+ * substrings.) Namely, each element of the iterator corresponds to text
485
+ * that *isn't* matched by the regular expression. The remainder of the
486
+ * string that is not split will be the last element in the iterator.
385
487
  *
386
- * const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
387
- * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
388
- * const caps = re.captures(text)
389
- * expect(caps.get[1].value).toBe("Citizen Kane")
390
- * expect(caps.get[2].value).toBe("1941")
391
- * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
392
- * ```
488
+ * This method will *not* copy the text given.
393
489
  *
394
- * Note that the full match is at capture group `0`. Each subsequent
395
- * capture group is indexed by the order of its opening `(`.
490
+ * # Example
396
491
  *
397
- * We can make this example a bit clearer by using *named* capture groups:
492
+ * Get the first two words in some text:
398
493
  *
399
494
  * ```typescript
400
495
  * import { RRegex } from "rregex"
401
496
  *
402
- * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
403
- * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
404
- * const caps = re.captures(text)
405
- * expect(caps.name["title"].value).toBe("Citizen Kane")
406
- * expect(caps.name["year"].value).toBe("1941")
407
- * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
497
+ * const re = new RRegex(r"\\W+")
498
+ * const fields = re.splitn("Hey! How are you?", 3)
499
+ * expect(fields).toEqual(["Hey", "How", "are you?"])
408
500
  * ```
409
- *
410
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
501
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
411
502
  * @param {string} text - The string against which to match the regular expression
412
- * @returns {Captures|undefined}
503
+ * @param {number} limit - Max number result elements
504
+ * @returns {string[]}
413
505
  */
414
- captures(text) {
506
+ splitn(text, limit) {
415
507
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
416
508
  const len0 = WASM_VECTOR_LEN;
417
- const ret = wasm.rregex_captures(this.__wbg_ptr, ptr0, len0);
509
+ const ret = wasm.rregex_splitn(this.__wbg_ptr, ptr0, len0, limit);
510
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
511
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
512
+ return v2;
513
+ }
514
+ /**
515
+ * Returns the regular expression into a high level intermediate
516
+ * representation.
517
+ * @returns {any}
518
+ */
519
+ syntax() {
520
+ const ret = wasm.rregex_syntax(this.__wbg_ptr);
418
521
  if (ret[2]) {
419
522
  throw takeFromExternrefTable0(ret[1]);
420
523
  }
421
524
  return takeFromExternrefTable0(ret[0]);
422
525
  }
423
526
  /**
424
- * Returns a list with all the non-overlapping capture groups matched
425
- * in `text`. This is operationally the same as `findAll`, except it
426
- * returns information about capturing group matches.
427
- *
428
- * # Example
429
- *
430
- * We can use this to find all movie titles and their release years in
431
- * some text, where the movie is formatted like "'Title' (xxxx)":
432
- *
433
- * ```typescript
434
- * import { RRegex } from "rregex"
527
+ * Returns the same as find, but starts the search at the given
528
+ * offset.
435
529
  *
436
- * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\\)")
437
- * const text = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931)."
438
- * for caps of re.captures_iter(text) {
439
- * console.log(
440
- * "Movie:", caps.name["title"].value, ","
441
- * "Released:", caps.name["year"].value
442
- * );
443
- * }
444
- * // Output:
445
- * // Movie: Citizen Kane, Released: 1941
446
- * // Movie: The Wizard of Oz, Released: 1939
447
- * // Movie: M, Released: 1931
448
- * ```
530
+ * The significance of the starting point is that it takes the surrounding
531
+ * context into consideration. For example, the `\A` anchor can only
532
+ * match when `start == 0`.
449
533
  *
450
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_iter
534
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_at
451
535
  * @param {string} text - The string against which to match the regular expression
452
- * @returns {Captures[]}
536
+ * @param {number} start - Zero-based index at which to start matching
537
+ * @returns {Match}
453
538
  */
454
- capturesAll(text) {
539
+ findAt(text, start) {
455
540
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
456
541
  const len0 = WASM_VECTOR_LEN;
457
- const ret = wasm.rregex_capturesAll(this.__wbg_ptr, ptr0, len0);
542
+ const ret = wasm.rregex_findAt(this.__wbg_ptr, ptr0, len0, start);
458
543
  if (ret[2]) {
459
544
  throw takeFromExternrefTable0(ret[1]);
460
545
  }
461
546
  return takeFromExternrefTable0(ret[0]);
462
547
  }
463
- /**
464
- * Returns the number of captures.
465
- *
466
- * This includes all named and unnamed groups, including the implicit
467
- * unnamed group that is always present and corresponds to the entire match.
468
- *
469
- * Since the implicit unnamed group is always included in this length, the
470
- * length returned is guaranteed to be greater than zero.
471
- *
472
- * ## Example
473
- *
474
- * ```typescript
475
- * import { RRegex } from "rregex"
476
- *
477
- * const re1 = new RRegex("(?P<y>\\d{4})-(?P<m>\\d{2})-(?P<d>\\d{2})")
478
- * expect(re1.capturesLength()).toEqual(4)
479
- *
480
- * const re2 = new RRegex("foo")
481
- * expect(re2.capturesLength()).toEqual(1)
482
- *
483
- * const re3 = new RRegex("(foo)")
484
- * expect(re3.capturesLength()).toEqual(2)
485
- *
486
- * const re4 = new RRegex("(?<a>.(?<b>.))(.)(?:.)(?<c>.)")
487
- * expect(re4.capturesLength()).toEqual(5)
488
- *
489
- * const re5 = new RRegex("[a&&b]")
490
- * expect(re5.capturesLength()).toEqual(1)
491
- * ```
492
- *
493
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures_len
494
- * @returns {number}
495
- */
496
- capturesLength() {
497
- const ret = wasm.rregex_capturesLength(this.__wbg_ptr);
498
- return ret >>> 0;
499
- }
500
548
  /**
501
549
  * Replaces the leftmost-first match with the replacement provided.
502
550
  * The replacement can be a regular string (where `$N` and `$name` are
@@ -589,197 +637,149 @@ class RRegex {
589
637
  }
590
638
  }
591
639
  /**
592
- * Replaces at most `limit` non-overlapping matches in `text` with the
593
- * replacement provided. If `limit` is 0, then all non-overlapping matches
594
- * are replaced.
595
- *
596
- * See the documentation for `replace` for details on how to access
597
- * capturing group matches in the replacement string.
598
- *
599
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
600
- * @param {string} text - The string against which to match the regular expression
601
- * @param {number} limit - Max number of replacement
602
- * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
603
- * @returns {string}
604
- */
605
- replacen(text, limit, rep) {
606
- let deferred3_0;
607
- let deferred3_1;
608
- try {
609
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
610
- const len0 = WASM_VECTOR_LEN;
611
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
612
- const len1 = WASM_VECTOR_LEN;
613
- const ret = wasm.rregex_replacen(this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
614
- deferred3_0 = ret[0];
615
- deferred3_1 = ret[1];
616
- return getStringFromWasm0(ret[0], ret[1]);
617
- } finally {
618
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
619
- }
620
- }
621
- /**
622
- * Replaces all non-overlapping matches in `text` with the replacement
623
- * provided. This is the same as calling `replacen` with `limit` set to
624
- * `0`.
625
- *
626
- * See the documentation for `replace` for details on how to access
627
- * capturing group matches in the replacement string.
628
- *
629
- * See the documentation for `replace` for details on how to access capturing group matches in the replacement string.
630
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
631
- * @param {string} text - The string against which to match the regular expression
632
- * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
633
- * @returns {string}
634
- */
635
- replaceAll(text, rep) {
636
- let deferred3_0;
637
- let deferred3_1;
638
- try {
639
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
640
- const len0 = WASM_VECTOR_LEN;
641
- const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
642
- const len1 = WASM_VECTOR_LEN;
643
- const ret = wasm.rregex_replaceAll(this.__wbg_ptr, ptr0, len0, ptr1, len1);
644
- deferred3_0 = ret[0];
645
- deferred3_1 = ret[1];
646
- return getStringFromWasm0(ret[0], ret[1]);
647
- } finally {
648
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
649
- }
650
- }
651
- /**
652
- * Returns an iterator of substrings of `text` delimited by a match of the
653
- * regular expression. Namely, each element of the iterator corresponds to
654
- * text that *isn't* matched by the regular expression.
640
+ * Returns the capture groups corresponding to the leftmost-first
641
+ * match in `text`. Capture group `0` always corresponds to the entire
642
+ * match. If no match is found, then `undefined` is returned.
655
643
  *
656
- * This method will *not* copy the text given.
644
+ * You should only use `captures` if you need access to the location of
645
+ * capturing group matches. Otherwise, `find` is faster for discovering
646
+ * the location of the overall match.
657
647
  *
658
- * # Example
648
+ * # Examples
659
649
  *
660
- * To split a string delimited by arbitrary amounts of spaces or tabs:
650
+ * Say you have some text with movie names and their release years,
651
+ * like "'Citizen Kane' (1941)". It'd be nice if we could search for text
652
+ * looking like that, while also extracting the movie name and its release
653
+ * year separately.
661
654
  *
662
655
  * ```typescript
663
656
  * import { RRegex } from "rregex"
664
657
  *
665
- * const re = new RRegex(r"[ \\t]+")
666
- * const fields = re.split("a b \t c\td e")
667
- * expect(fields).toEqual(["a", "b", "c", "d", "e"])
658
+ * const re = new RRegex("'([^']+)'\\s+\\((\\d{4})\)")
659
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
660
+ * const caps = re.captures(text)
661
+ * expect(caps.get[1].value).toBe("Citizen Kane")
662
+ * expect(caps.get[2].value).toBe("1941")
663
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
668
664
  * ```
669
665
  *
670
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.split
666
+ * Note that the full match is at capture group `0`. Each subsequent
667
+ * capture group is indexed by the order of its opening `(`.
668
+ *
669
+ * We can make this example a bit clearer by using *named* capture groups:
670
+ *
671
+ * ```typescript
672
+ * import { RRegex } from "rregex"
673
+ *
674
+ * const re = new RRegex("'(?P<title>[^']+)'\\s+\\((?P<year>\\d{4})\)")
675
+ * const text = "Not my favorite movie: 'Citizen Kane' (1941)."
676
+ * const caps = re.captures(text)
677
+ * expect(caps.name["title"].value).toBe("Citizen Kane")
678
+ * expect(caps.name["year"].value).toBe("1941")
679
+ * expect(caps.get[0].value).toBe("'Citizen Kane' (1941)")
680
+ * ```
681
+ *
682
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.captures
671
683
  * @param {string} text - The string against which to match the regular expression
672
- * @returns {string[]}
684
+ * @returns {Captures|undefined}
673
685
  */
674
- split(text) {
686
+ captures(text) {
675
687
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
676
688
  const len0 = WASM_VECTOR_LEN;
677
- const ret = wasm.rregex_split(this.__wbg_ptr, ptr0, len0);
678
- var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
679
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
680
- return v2;
689
+ const ret = wasm.rregex_captures(this.__wbg_ptr, ptr0, len0);
690
+ if (ret[2]) {
691
+ throw takeFromExternrefTable0(ret[1]);
692
+ }
693
+ return takeFromExternrefTable0(ret[0]);
681
694
  }
682
695
  /**
683
- * Returns an iterator of at most `limit` substrings of `text` delimited
684
- * by a match of the regular expression. (A `limit` of `0` will return no
685
- * substrings.) Namely, each element of the iterator corresponds to text
686
- * that *isn't* matched by the regular expression. The remainder of the
687
- * string that is not split will be the last element in the iterator.
688
- *
689
- * This method will *not* copy the text given.
696
+ * Returns an array for each successive non-overlapping match in `text``,
697
+ * returning the start and end byte indices with respect to `text`.
690
698
  *
691
699
  * # Example
692
700
  *
693
- * Get the first two words in some text:
701
+ * Find the start and end location of every word with exactly 13 Unicode
702
+ * word characters:
694
703
  *
695
704
  * ```typescript
696
705
  * import { RRegex } from "rregex"
697
706
  *
698
- * const re = new RRegex(r"\\W+")
699
- * const fields = re.splitn("Hey! How are you?", 3)
700
- * expect(fields).toEqual(["Hey", "How", "are you?"])
707
+ * const text = "Retroactively relinquishing remunerations is reprehensible."
708
+ * const matches = new RRegex("\\b\\w{13}\\b").findAll(text)
701
709
  * ```
702
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.splitn
710
+ *
711
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.find_iter
703
712
  * @param {string} text - The string against which to match the regular expression
704
- * @param {number} limit - Max number result elements
705
- * @returns {string[]}
713
+ * @returns {Match}
706
714
  */
707
- splitn(text, limit) {
715
+ findAll(text) {
708
716
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
709
717
  const len0 = WASM_VECTOR_LEN;
710
- const ret = wasm.rregex_splitn(this.__wbg_ptr, ptr0, len0, limit);
711
- var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
712
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
713
- return v2;
718
+ const ret = wasm.rregex_findAll(this.__wbg_ptr, ptr0, len0);
719
+ if (ret[2]) {
720
+ throw takeFromExternrefTable0(ret[1]);
721
+ }
722
+ return takeFromExternrefTable0(ret[0]);
714
723
  }
715
724
  /**
716
- * Returns the end location of a match in the text given.
717
- *
718
- * This method may have the same performance characteristics as
719
- * `isMatch`, except it provides an end location for a match. In
720
- * particular, the location returned *may be shorter* than the proper end
721
- * of the leftmost-first match that you would find via `Regex.find`.
725
+ * Returns true if and only if there is a match for the regex in the
726
+ * string given.
722
727
  *
723
- * Note that it is not guaranteed that this routine finds the shortest or
724
- * "earliest" possible match. Instead, the main idea of this API is that
725
- * it returns the offset at the point at which the internal regex engine
726
- * has determined that a match has occurred. This may vary depending on
727
- * which internal regex engine is used, and thus, the offset itself may
728
- * change.
728
+ * It is recommended to use this method if all you need to do is test
729
+ * a match, since the underlying matching engine may be able to do less
730
+ * work.
729
731
  *
730
732
  * # Example
731
733
  *
732
- * Typically, `a+` would match the entire first sequence of `a` in some
733
- * text, but `shortest_match` can give up as soon as it sees the first
734
- * `a`.
734
+ * Test if some text contains at least one word with exactly 13
735
+ * Unicode word characters:
735
736
  *
736
737
  * ```typescript
737
738
  * import { RRegex } from "rregex"
738
739
  *
739
- * const text = "aaaaa"
740
- * const = new RRegex("a+").shortest_match(text)
741
- * expect(pos).toBe(1)
740
+ * const text = "I categorically deny having triskaidekaphobia."
741
+ * expect(new RRegex("\\b\\w{13}\\b").is_match(text)).toBe(true)
742
742
  * ```
743
743
  *
744
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match
744
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.is_match
745
745
  * @param {string} text - The string against which to match the regular expression
746
- * @returns {number|undefined}
746
+ * @return {boolean}
747
747
  */
748
- shortestMatch(text) {
748
+ isMatch(text) {
749
749
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
750
750
  const len0 = WASM_VECTOR_LEN;
751
- const ret = wasm.rregex_shortestMatch(this.__wbg_ptr, ptr0, len0);
752
- return ret === 0x100000001 ? undefined : ret;
751
+ const ret = wasm.rregex_isMatch(this.__wbg_ptr, ptr0, len0);
752
+ return ret !== 0;
753
753
  }
754
754
  /**
755
- * Returns the same as `shortest_match`, but starts the search at the
756
- * given offset.
755
+ * Replaces at most `limit` non-overlapping matches in `text` with the
756
+ * replacement provided. If `limit` is 0, then all non-overlapping matches
757
+ * are replaced.
757
758
  *
758
- * The significance of the starting point is that it takes the surrounding
759
- * context into consideration. For example, the `\A` anchor can only match
760
- * when `start == 0`.
761
- * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.shortest_match_at
759
+ * See the documentation for `replace` for details on how to access
760
+ * capturing group matches in the replacement string.
761
+ *
762
+ * @see https://docs.rs/regex/latest/regex/struct.Regex.html#method.replacen
762
763
  * @param {string} text - The string against which to match the regular expression
763
- * @param {number} start - Zero-based index at which to start matching
764
- * @returns {number|undefined}
765
- */
766
- shortestMatchAt(text, start) {
767
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
768
- const len0 = WASM_VECTOR_LEN;
769
- const ret = wasm.rregex_shortestMatchAt(this.__wbg_ptr, ptr0, len0, start);
770
- return ret === 0x100000001 ? undefined : ret;
771
- }
772
- /**
773
- * Returns the regular expression into a high level intermediate
774
- * representation.
775
- * @returns {any}
764
+ * @param {number} limit - Max number of replacement
765
+ * @param {string} rep - It's a string, it will replace the substring matched by `pattern`.
766
+ * @returns {string}
776
767
  */
777
- syntax() {
778
- const ret = wasm.rregex_syntax(this.__wbg_ptr);
779
- if (ret[2]) {
780
- throw takeFromExternrefTable0(ret[1]);
768
+ replacen(text, limit, rep) {
769
+ let deferred3_0;
770
+ let deferred3_1;
771
+ try {
772
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
773
+ const len0 = WASM_VECTOR_LEN;
774
+ const ptr1 = passStringToWasm0(rep, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
775
+ const len1 = WASM_VECTOR_LEN;
776
+ const ret = wasm.rregex_replacen(this.__wbg_ptr, ptr0, len0, limit, ptr1, len1);
777
+ deferred3_0 = ret[0];
778
+ deferred3_1 = ret[1];
779
+ return getStringFromWasm0(ret[0], ret[1]);
780
+ } finally {
781
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
781
782
  }
782
- return takeFromExternrefTable0(ret[0]);
783
783
  }
784
784
  /**
785
785
  * Returns a string representing the regular expression
@@ -855,43 +855,6 @@ class RRegexSet {
855
855
  RRegexSetFinalization.register(this, this.__wbg_ptr, this);
856
856
  return this;
857
857
  }
858
- /**
859
- * Returns true if and only if one of the regexes in this set matches
860
- * the text given.
861
- *
862
- * This method should be preferred if you only need to test whether any
863
- * of the regexes in the set should match, but don't care about *which*
864
- * regexes matched. This is because the underlying matching engine will
865
- * quit immediately after seeing the first match instead of continuing to
866
- * find all matches.
867
- *
868
- * Note that as with searches using `Regex`, the expression is unanchored
869
- * by default. That is, if the regex does not start with `^` or `\A`, or
870
- * end with `$` or `\z`, then it is permitted to match anywhere in the
871
- * text.
872
- *
873
- * # Example
874
- *
875
- * Tests whether a set matches some text:
876
- *
877
- * ```typescript
878
- * import { RegexSet } from "rregex"
879
- *
880
- * const set = new RegexSet(["\\w+", "\\d+"])
881
- * expect(set.is_match("foo")).toBe(true)
882
- * expect(!set.is_match("☃")).toBe(false)
883
- * ```
884
- *
885
- * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
886
- * @param {string} text - The string against which to match the regular expression
887
- * @return {boolean}
888
- */
889
- isMatch(text) {
890
- const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
891
- const len0 = WASM_VECTOR_LEN;
892
- const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
893
- return ret !== 0;
894
- }
895
858
  /**
896
859
  * Returns the set of regular expressions that match in the given text.
897
860
  *
@@ -938,60 +901,97 @@ class RRegexSet {
938
901
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
939
902
  return v2;
940
903
  }
904
+ /**
905
+ * Returns true if and only if one of the regexes in this set matches
906
+ * the text given.
907
+ *
908
+ * This method should be preferred if you only need to test whether any
909
+ * of the regexes in the set should match, but don't care about *which*
910
+ * regexes matched. This is because the underlying matching engine will
911
+ * quit immediately after seeing the first match instead of continuing to
912
+ * find all matches.
913
+ *
914
+ * Note that as with searches using `Regex`, the expression is unanchored
915
+ * by default. That is, if the regex does not start with `^` or `\A`, or
916
+ * end with `$` or `\z`, then it is permitted to match anywhere in the
917
+ * text.
918
+ *
919
+ * # Example
920
+ *
921
+ * Tests whether a set matches some text:
922
+ *
923
+ * ```typescript
924
+ * import { RegexSet } from "rregex"
925
+ *
926
+ * const set = new RegexSet(["\\w+", "\\d+"])
927
+ * expect(set.is_match("foo")).toBe(true)
928
+ * expect(!set.is_match("☃")).toBe(false)
929
+ * ```
930
+ *
931
+ * @see https://docs.rs/regex/latest/regex/struct.RegexSet.html#method.is_match
932
+ * @param {string} text - The string against which to match the regular expression
933
+ * @return {boolean}
934
+ */
935
+ isMatch(text) {
936
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
937
+ const len0 = WASM_VECTOR_LEN;
938
+ const ret = wasm.rregexset_isMatch(this.__wbg_ptr, ptr0, len0);
939
+ return ret !== 0;
940
+ }
941
941
  }
942
942
  module.exports.RRegexSet = RRegexSet;
943
943
 
944
- module.exports.__wbg_buffer_61b7ce01341d7f88 = function(arg0) {
944
+ module.exports.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
945
945
  const ret = arg0.buffer;
946
946
  return ret;
947
947
  };
948
948
 
949
- module.exports.__wbg_fromCodePoint_ef89154c4db48bdf = function() { return handleError(function (arg0) {
949
+ module.exports.__wbg_fromCodePoint_f37c25c172f2e8b5 = function() { return handleError(function (arg0) {
950
950
  const ret = String.fromCodePoint(arg0 >>> 0);
951
951
  return ret;
952
952
  }, arguments) };
953
953
 
954
- module.exports.__wbg_from_d68eaa96dba25449 = function(arg0) {
954
+ module.exports.__wbg_from_2a5d3e218e67aa85 = function(arg0) {
955
955
  const ret = Array.from(arg0);
956
956
  return ret;
957
957
  };
958
958
 
959
- module.exports.__wbg_get_9aa3dff3f0266054 = function(arg0, arg1) {
959
+ module.exports.__wbg_get_b9b93047fe3cf45b = function(arg0, arg1) {
960
960
  const ret = arg0[arg1 >>> 0];
961
961
  return ret;
962
962
  };
963
963
 
964
- module.exports.__wbg_length_d65cf0786bfc5739 = function(arg0) {
964
+ module.exports.__wbg_length_e2d2a49132c1b256 = function(arg0) {
965
965
  const ret = arg0.length;
966
966
  return ret;
967
967
  };
968
968
 
969
- module.exports.__wbg_new_254fa9eac11932ae = function() {
970
- const ret = new Array();
969
+ module.exports.__wbg_new_405e22f390576ce2 = function() {
970
+ const ret = new Object();
971
971
  return ret;
972
972
  };
973
973
 
974
- module.exports.__wbg_new_3ff5b33b1ce712df = function(arg0) {
975
- const ret = new Uint8Array(arg0);
974
+ module.exports.__wbg_new_78feb108b6472713 = function() {
975
+ const ret = new Array();
976
976
  return ret;
977
977
  };
978
978
 
979
- module.exports.__wbg_new_688846f374351c92 = function() {
980
- const ret = new Object();
979
+ module.exports.__wbg_new_a12002a7f91c75be = function(arg0) {
980
+ const ret = new Uint8Array(arg0);
981
981
  return ret;
982
982
  };
983
983
 
984
- module.exports.__wbg_newwithbyteoffsetandlength_ba35896968751d91 = function(arg0, arg1, arg2) {
984
+ module.exports.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
985
985
  const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
986
986
  return ret;
987
987
  };
988
988
 
989
- module.exports.__wbg_push_6edad0df4b546b2c = function(arg0, arg1) {
989
+ module.exports.__wbg_push_737cfc8c1432c2c6 = function(arg0, arg1) {
990
990
  const ret = arg0.push(arg1);
991
991
  return ret;
992
992
  };
993
993
 
994
- module.exports.__wbg_set_1d80752d0d5f0b21 = function(arg0, arg1, arg2) {
994
+ module.exports.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
995
995
  arg0[arg1 >>> 0] = arg2;
996
996
  };
997
997
 
@@ -999,7 +999,7 @@ module.exports.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
999
999
  arg0[arg1] = arg2;
1000
1000
  };
1001
1001
 
1002
- module.exports.__wbg_set_4e647025551483bd = function() { return handleError(function (arg0, arg1, arg2) {
1002
+ module.exports.__wbg_set_bb8cecf6a62b9f46 = function() { return handleError(function (arg0, arg1, arg2) {
1003
1003
  const ret = Reflect.set(arg0, arg1, arg2);
1004
1004
  return ret;
1005
1005
  }, arguments) };