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