rregex 1.11.0 → 1.12.0

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